How to check if UIDocumentInteractionController will fail to open document due to missing external application on iPad?

后端 未结 5 1528
独厮守ぢ
独厮守ぢ 2020-12-13 20:58

I am using UIDocumentInteractionController for showing popover menu \"Open In...\" so that user can open a document in other application.

Method p

5条回答
  •  猫巷女王i
    2020-12-13 21:43

    [EDIT] Not working for iOS 6.0 (see comment)

    It seems that dismissMenuAnimated (with no animation at all) is the key:

    -(BOOL)canOpenDocumentWithURL:(NSURL*)url inView:(UIView*)view {
        BOOL canOpen = NO;
        UIDocumentInteractionController* docController = [UIDocumentInteractionController 
                                                       interactionControllerWithURL:url];
        if (docController)
        {
            docController.delegate = self;
            canOpen = [docController presentOpenInMenuFromRect:CGRectZero
                                       inView:self.view animated:NO];                   
            [docController dismissMenuAnimated:NO];
        }
        return canOpen;
    }
    

    It will return YES if at least one application is able to open the file pointed by url. At least it's working in my case (KMZ files), testing with/without Dropbox app on iPhone iOS 4.3.
    Actually, it seems to work even if url is not pointing to an actual file (i.e. @"test.kmz"), but I wouldn't rely on it for all file types.

提交回复
热议问题