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

后端 未结 2 1698
时光说笑
时光说笑 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条回答
  •  -上瘾入骨i
    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
    }
    

提交回复
热议问题