File sharing / send file in another app (“open in” in iOS)

梦想与她 提交于 2019-12-03 12:13:54

Its a memory management issue. The main reason it crashes is because the object is not retained. Thats why if you declare it in the .h file and write an @property for retain when you do assign it the object gets retained.

So in your interface file (.h) you should have

@property (retain)UIDocumentInteractionController *documentController;

Then in your .m (implementation file) you can do

@synthesize documentController;

- (void)openDocumentIn{

    // Some code here

    self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
        documentController.delegate = self;
    documentController.UTI = @"public.text";
    [documentController presentOpenInMenuFromRect:CGRectZero
                                   inView:self.view
                                 animated:YES];
    // Some more stuff
}

Here is how it works for me :

I just put the declaration "UIDocumentInteractionController *documentController" in the .h file and it works !

I really don't know why, but ....

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