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

后端 未结 2 1707
时光说笑
时光说笑 2021-02-14 14:03

my app make a simple file called log.txt

the URL of this file (viewed in xcode) is file://localhost/var/mobile/Applications/NUMBER OF THE APPLICATION/Documents/

相关标签:
2条回答
  • 2021-02-14 14:24

    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 ....

    0 讨论(0)
  • 2021-02-14 14:25

    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
    }
    
    0 讨论(0)
提交回复
热议问题