当调用UIActivityViewController时,IOS 8 iPad App崩溃 [英] IOS 8 iPad App Crashes When UIActivityViewController Is Called
问题描述
当在这个应用程序的iPhone上调用UIActivityViewController时,它工作得很好,但是当在iPad上调用时,应用程序崩溃。下面是我使用的代码:
When a UIActivityViewController is called on the iPhone in this app, it works perfectly, but when called on a iPad, the app crashes. Below is the code I used:
func shareButtonPress() {
//when the share button is pressed, default share phrase is added, cropped image of highscore is added
var sharingItems = [AnyObject]()
var shareButtonHighscore = NSUserDefaults.standardUserDefaults().objectForKey("highscore") as Int!
sharingItems.append("Just hit \(shareButtonHighscore)! Beat it! #Swath")
UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size, false, 0);
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
sharingItems.append(image)
let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)
var barButtonItem: UIBarButtonItem! = UIBarButtonItem()
activityViewController.excludedActivityTypes = [UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo]
self.presentViewController(activityViewController, animated: true, completion: nil)
}
我在SpriteKit框架中的Swift编程,我不明白为什么应用程序崩溃。
As you can see, I'm programming in Swift, in the SpriteKit Framework, and I don't understand why the app is crashing.
我收到此错误:
Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7fc7a874bd90>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
我可以如何解决这个问题?
What can I do to fix this problem?
推荐答案
在呈现 UIActivityViewController
之前,添加这行代码:
Before presenting the UIActivityViewController
, add in this line of code:
activityViewController.popoverPresentationController?.sourceView = self.view
这样,视图控制器知道GameViewController的哪个框架出现。
This way, the view controller knows in which frame of the GameViewController to appear in.
这篇关于当调用UIActivityViewController时,IOS 8 iPad App崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!