• 关于UIDocumentInteractionController使用问题


    1、调用问题

    在使用UIDocumentInteractionController的时候不能使用局部变量形式调用。
    比如

            UIDocumentInteractionController * documentInteraction = [UIDocumentInteractionController interactionControllerWithURL:[NSURL URLWithString:fileLocalPath]];
            [documentInteraction presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
    
    • 1
    • 2

    这样调用后UIDocumentInteractionController 释放了界面就没了,你始终是调用不了。
    解决方法:
    你可以用成员变量形式来解决,代码如下

    #pragma mark - Lazy
    - (UIDocumentInteractionController *)documentInteraction{
        if (!_documentInteraction) {
            _documentInteraction = [[UIDocumentInteractionController alloc] init];
            _documentInteraction.delegate = self;
        }
        return _documentInteraction;
    }
    
    //调用
    self.documentInteraction.URL = [NSURL fileURLWithPath:filesLocalPath];
    [self.documentInteraction presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    2、点击其他App分享问题

    2.1 点击后界面弹出个空界面。

    不要在代理函数中如以下函数中调用释放UIDocumentInteractionController

    - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller
    
    - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller;
    
    • 1
    • 2
    • 3

    释放代码

    self.documentInteraction = nil;
    
    • 1

    因为有一些第三方App(word、QQ浏览器)要跳入其他App打开文件的,跳过去的时候他们就帮你把其关闭了。
    会调用以上代码中的函数, 那UIDocumentInteractionController 释放了,第三方就打不开了。
    千万不要写释放,利用ARC让其释放。

    2.2 先点击一个分享后,回到App再点击分享后没有反应。

    这种情况只发生在点击分享后,这个分享调用第三方App,并且UIDocumentInteractionController 没有关闭(有些分享会关有些不会关)。例如使用word App分享文件就不会关闭UIDocumentInteractionController。然后你回到自己的App的时候再点击分享就没有用了。(目前发现微信App 也存在这个问题)
    解决方法:

    - (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(nullable NSString *)application{
        [self.documentInteraction dismissMenuAnimated:YES];
    }
    
    • 1
    • 2
    • 3

    在点击分享跳入第三方App 的时候统一关闭UIDocumentInteractionController。

  • 相关阅读:
    宏观经济学通识课-读书笔记
    目前最流行的无人机摄影测量软件有哪些?各有什么特点?
    哪种主机更适合初创公司租用?云主机与共享主机
    SSH免密登陆 配置方法(Mac、Win)
    跨境电商新趋势:海外盲盒小程序的市场机遇
    图论进阶之路-最小生成树模版
    机房环境监控什么意思?机房环境监控系统作用
    经纬度转笛卡尔坐标
    【老生谈算法】matlab实现LU分解算法源码——LU算法
    Apipost自动化测试
  • 原文地址:https://blog.csdn.net/sky_long_fly/article/details/120336651