iOS UIDocumentInteractionController LaunchServices: invalidationHandler called

对着背影说爱祢 提交于 2019-12-11 11:15:10

问题


I'm having an issue when I try to Launch Instagram from my app. Everything works and I'm able to launch IG and even see the photo I sent etc.

The problem is that the UIDocumentInteractionController is crashing my app. And YES I have done my research.

I've seen the posts LIKE THIS that indicate that this is an Apple bug as as long as you can fix the crash, you should be able fine and ignore the Launch Services message.

The problem is I am still having the crash and trying to figure out how to resolve it.

I found a post that talks about adding an IF-STATEMENT after presenting the ViewController HERE, this post was written in Objective-C, and the example was not for a UIDocumentInteractionController.

I tried to take a stab at it in Swift, but it is still not working out for me. Would appreciate if someone can help out.

dic = UIDocumentInteractionController(URL: imageURL!)
dic.delegate = self

var annotationDictionary: [String: String] = ["InstagramCaption": "Test"]
dic.annotation = annotationDictionary
dic.UTI = "com.instagram.exclusivegram"

dic.presentOpenInMenuFromRect(CGRectMake(1, 1, 1, 1), inView: self.view, animated: true)

if dic.respondsToSelector("popoverPresentationController") {

    Scripts.log("InstagramVC Did Respond to popoverPresentationController")     
    var popoverController: UIPopoverPresentationController = self.popoverPresentationController!        
    popoverPresentationController?.sourceView = self.view       
}

回答1:


The fix in my case was to declare the UIDocumentInteractionController variable as part of the viewcontroller's class instead of creating it in the same function where I set up the annotation and UTI and called .presentOpenInMenuFromRect

So near the top of my class outside of any functions I declared the variable:

var docController = UIDocumentInteractionController()

And then when I was ready to use it, I configured everything about the already existing UIDocumentInteractionController instead of creating one:

docController = UIDocumentInteractionController(URL: imageURL!)
docController.UTI = "com.instagram.exclusivegram"
docController.delegate = self
docController.annotation = ["InstagramCaption":"Text"]

docController.presentOpenInMenuFromRect(rect, inView: self.view, animated: true)

The app stopped crashing and Instagram now loads with the image/text assigned. 😃👍

I found the suggestion that led me to this fix here: https://stackoverflow.com/a/16057399/428981 and then adapted for Swift




回答2:


It sounds like your instance of UIDocumentInteractionController is going out of scope. Try making it a property on the class or some other way to retain it.




回答3:


I had the same problem: sending the picture to Instagram worked but instantaneously crashed my app. I think it has something to do with how the UIDocumentInteractionController is handled by the system once another app opens. If you try to send the picture via the embedded Facebook or Twitter frameworks that open a popover on top of your app, then no crash happens...

In any case the way I finally made it work is by NOT declaring my viewController as delegate, so:

// dic.delegate = self

The downside being that you can't use any of the delegate methods. In my case I wasn't using them anyway.



来源:https://stackoverflow.com/questions/29065772/ios-uidocumentinteractioncontroller-launchservices-invalidationhandler-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!