iOS:如果使用 "Message"选项共享则崩溃

标签 ios swift uiactivityviewcontroller mfmessagecomposeviewcontroller

我们的应用仅支持纵向模式。呈现 UIActivityViewController 有效。

但是,使用“消息”选项共享会使应用程序崩溃:

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [MFMessageComposeViewController shouldAutorotate] is returning YES'

与其他选项共享,例如 Facebook Messenger,有效。

类似 SO 问题的解决方案 like this one不工作,因为他们建议支持所有方向。我们只想支持纵向。

1)我们如何在仅支持纵向的情况下支持“消息”共享选项,即在 Info.plist 中仅支持纵向?

2) 为什么我们能够在其他应用程序中支持“消息”共享选项,而在 Info.plist 中只有纵向方向,但不能支持这个?我们应该在哪里寻找调试目的?

    // 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)

最佳答案

我尝试了一段时间来重现这个错误,但没能让它崩溃。最后,当我返回 UIInterfaceOrientationPortrait 时,当我应该为其中一个方向函数返回 UIInterfaceOrientationMaskPortrait 时,我终于能够得到这个确切的崩溃。检查 View Controller 对 supportedInterfaceOrientations 的实现和 application:supportedInterfaceOrientationsForWindow:

的实现

关于iOS:如果使用 "Message"选项共享则崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41233783/

相关文章:

iOS 控制 UIScrollView 的滚动位置?

ios - 我们可以使用代码为 Storyboard的 View Controller 提供类名(自定义类)吗?

ios - 旋转 ImageView 动画

自定义 UIActivityType 的 Objective-C 版本

ios - 在 iOS 8 上将视频分享到 Facebook

android - Android 中的 View.Frame 等价物

android - iOS ARCore - 如何使用 ARCore 连接 Android 和 iOS 设备并发送和接收 AR 对象?

ios - 更改 iOS 中的第一个 ViewController

ios - 使用企业配置文件签署 swift 应用程序

ios7 - 当从 iOS7 中的 UIActivityViewController 呈现时,无法设置邮件编辑器中“发送”和“取消”按钮的文本颜色