Uiactivityviewcontroller Crashing on iOS 8 Ipads

UIActivityViewController crashing on iOS 8 iPads

On iPad the activity view controller will be displayed as a popover using the new UIPopoverPresentationController, it requires that you specify an anchor point for the presentation of the popover using one of the three following properties:

  • barButtonItem
  • sourceView
  • sourceRect

In order to specify the anchor point you will need to obtain a reference to the UIActivityController's UIPopoverPresentationController and set one of the properties as follows:

if ( [activityViewController respondsToSelector:@selector(popoverPresentationController)] ) { 
// iOS8
activityViewController.popoverPresentationController.sourceView =
parentView;
}

IOS 8 iPad App Crashes When UIActivityViewController Is Called

Before presenting the UIActivityViewController, add in this line of code:

activityViewController.popoverPresentationController?.sourceView = self.view

This way, the view controller knows in which frame of the GameViewController to appear in.

UIActivityViewController crashing on iPad with sourceView or barButtonItem

You aren't initialising the activityViewController on iPad so it will always be nil.

Try:

- (void)shareLeaflet
{
NSString *forwardedString = [[NSString alloc] initWithFormat:@"Check out this leaflet\n\n %@ \n\nself.theURLToShare];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:forwardedString, nil] applicationActivities:nil];

if (IDIOM == IPAD)
{
NSLog(@"iPad");
activityViewController.popoverPresentationController.sourceView = self.view;
// activityViewController.popoverPresentationController.sourceRect = self.frame;
[self presentViewController:activityViewController
animated:YES
completion:nil];
}
else
{
NSLog(@"iPhone");
[self presentViewController:activityViewController
animated:YES
completion:nil];
}

And then to display it like in the image: (_shareBarButton is the UIBarButtonItem that you want the popover to display from)

- (void)shareLeaflet
{
NSString *forwardedString = [[NSString alloc] initWithFormat:@"Check out this leaflet\n\n %@ \n\nself.theURLToShare];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:forwardedString, nil] applicationActivities:nil];

if (IDIOM == IPAD)
{
NSLog(@"iPad");
activityViewController.popoverPresentationController.sourceView = self.view;
// activityViewController.popoverPresentationController.sourceRect = self.frame;

_popover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
_popover.delegate = self;
[_popover presentPopoverFromBarButtonItem:_shareBarButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
{
NSLog(@"iPhone");
[self presentViewController:activityViewController
animated:YES
completion:nil];
}

UIActivityViewController not working on iPad? iOS 8

You must add a source view.

Try to add this line :

activityVC.popoverPresentationController.sourceView = self.view;

You can also add the arrow direction :

activityVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionRight;
activityVC.popoverPresentationController.sourceView = sender;

UIActivityViewController in Swift Crashes on iPad

The UIActivityViewController's has non-null popoverPresentationController property when running on iPad. So, try below.

if let wPPC = activityVC.popoverPresentationController {
wPPC.sourceView = some view
// or
wPPC.barButtonItem = some bar button item
}
presentViewController( activityVC, animated: true, completion: nil )

UIActivityViewController crashing in iOS 8

The issue no longer exists using Xcode 6 beta 2

My iOS app crashes trying to display a UIActivityViewController

On iPad, UIActivityViewController needs to be presented in a popover or the app will crash, see this answer for details.

UIActivityViewController crashes when cancelling on iPhone iOS8

Thanks to @Y.Bonafons

I didn't set my delegate to nil in the previous controller after pop'ing, that's why it was trying to call it's methods.

Enabling Zombie Objects helps me a lot.



Related Topics



Leave a reply



Submit