Our app only supports portrait mode. Presenting a UIActivityViewController works.
However, sharing with the "Message" option crashes the app:
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [MFMessageComposeViewController shouldAutorotate] is returning YES'
Sharing with another option, such as Facebook Messenger, works.
Solutions from similar SO questions like this one do not work since they suggest supporting all orientations. We only want to support portrait.
1) How can we support the "Message" share option while only supporting portrait orientation, that is while only supporting portrait orientation in Info.plist?
2) Why are we able to support the "Message" share option in other apps with only portrait orientation in Info.plist but not this one? Where should we look for debugging purposes?
// Define share objects
let objectsToShare = ["test message"] as [Any]
// Configure UIActivityViewController
let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityViewController.excludedActivityTypes =
[UIActivityType.addToReadingList,
UIActivityType.assignToContact,
UIActivityType.print,
UIActivityType.copyToPasteboard]
// Define completion handler
activityViewController.completionWithItemsHandler = doneSharingHandler
// Show UIActivityViewController
present(activityViewController, animated: true, completion: nil)
I tried for a while to reproduce this bug and could not get it to crash. Finally I was able to get this exact crash when I returned UIInterfaceOrientationPortrait
when I should have been returning UIInterfaceOrientationMaskPortrait
for one of the orientation functions. Check your view controller's implementation of supportedInterfaceOrientations
and your implementation of application:supportedInterfaceOrientationsForWindow: