Swift中的UIActivityViewController在iPad上崩溃 [英] UIActivityViewController in Swift Crashes on iPad
本文介绍了Swift中的UIActivityViewController在iPad上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在我的游戏中制作共享功能,我有代码,它在iPhone上工作正常但是当我在iPad上测试时,当我点击分享按钮时应用程序崩溃。我使用以下代码进行分享按钮
I am making a share function in my game and I have the code and it works fine on iPhone but when I test it on a iPad, when I tap the share button the app crashes. I am using the following code for the share button
let textToShare = "Check out this website!"
if let myWebsite = NSURL(string: "http://www.apple.com/") {
let objectsToShare = [textToShare, myWebsite]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
self.view?.window?.rootViewController?.presentViewController(activityVC, animated: true, completion: nil)
}
推荐答案
在iPad上运行时,UIActivityViewController具有非null的popoverPresentationController属性。所以,请尝试以下。
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 )
这篇关于Swift中的UIActivityViewController在iPad上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文