Sharing Button Works Perfectly on iPhone But Crash on Ipad

Sharing button works perfectly on iPhone but crash on iPad

For ipad (iOS > 8.0) you need to set popoverPresentationController:

//check ipad
if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
//ios > 8.0
if ( activityVC.respondsToSelector(Selector("popoverPresentationController"))){
activityVC.popoverPresentationController?.sourceView = super.view
}
}

self.presentViewController(activityVC, animated: true, completion: nil)

More information here:
UIActivityViewController crashing on iOS 8 iPads

swift share button works in simulator not in device

The problem is that you're trying to present the view controller in an unsupported manner.

Here's the quote from Apple's UIActivityViewController Documentation:

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.

So, you should put a check in to see which type of device you have an present it differently based upon that. For instance, here's the way to check the device type (written in Obj-C, but should be easy to translate):

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The app is running on an iPad, so you have to wrap it in a UIPopOverController
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:activityVC];

// Option 1: If your "share" button is a UIBarButtonItem
[popOver presentPopoverFromBarButtonItem:barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

// Option 2: If your "share" button is NOT a UIBarButtonItem
[popOver presentPopoverFromRect:someRect inView:someView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
// The app is running on an iPod Touch or iPhone
// Use the same code you already have here...
[self presentViewController:activityVC animated:YES completion:nil];
}


Edit: (new code supplied for Swift by naturalc)

if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
// The app is running on an iPad, so you have to wrap it in a UIPopOverController
var popOver: UIPopoverController = UIPopoverController(contentViewController: activityVC)

// if your "share" button is a UIBarButtonItem
popOver.presentPopoverFromBarButtonItem(self.shareButton, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)

} else {
self.presentViewController(activityVC, animated: true, completion: nil)

}

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;
}

App crashes when presenting UIActivityController in iPad

As the error suggests, you need to add a sourceView to your popoverPresentationController.

controller.popoverPresentationController?.sourceView = sender as! UIView

App Crashed at launch, rejected by Apple

The iPad simply doesn't have the camera flash. So you can't use it. If you are using AVCaptureDevice or something similar, you must make sure that the app won't access the auto flash mode. Or the app will crash.

// Example //
class CameraViewController: BasicViewController, AVCapturePhotoCaptureDelegate {
@IBOutlet weak var flashSegcontrol: UISegmentedControl! // flashSegcontrol

func snapPicture() {
let settingsForMonitoring = AVCapturePhotoSettings()
if flashSegcontrol.selectedSegmentIndex == 0 {
if !isDeviceIpad() {
settingsForMonitoring.flashMode = .on
} else {
settingsForMonitoring.flashMode = .off
}
}
else if flashSegcontrol.selectedSegmentIndex == 1 {
settingsForMonitoring.flashMode = .off
}
else {
if !isDeviceIpad() {
settingsForMonitoring.flashMode = .auto
} else {
settingsForMonitoring.flashMode = .off
}
}
settingsForMonitoring.isAutoStillImageStabilizationEnabled = true
settingsForMonitoring.isHighResolutionPhotoEnabled = false
imagePhotoOutput?.capturePhoto(with: settingsForMonitoring, delegate: self as AVCapturePhotoCaptureDelegate)
}

func isDeviceIpad() -> Bool {
if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad {
return true
} else {
return false
}
}
}


Related Topics



Leave a reply



Submit