简体   繁体   English

UIDocumentInteractionController 菜单不会关闭(React Native 0.61.5)iOS 13+

[英]UIDocumentInteractionController menu does not dismiss (React Native 0.61.5) iOS 13+

I have an issue with UIDocumentInteractionController which is used to open a PDF document.我对用于打开 PDF 文档的 UIDocumentInteractionController 有问题。

The problem at this point is when user interacts with the menu my clicking on the Open in {app_name} action, the menu itself fails to close after user interaction leaving the menu open when user comes back to the app.此时的问题是,当用户与我点击 Open in {app_name} 操作的菜单交互时,当用户返回应用程序时,菜单本身无法在用户交互后关闭菜单。

Dismissing the menu at this point requires user to tap twice on the X in order for menu to be dismissed.此时关闭菜单需要用户在 X 上点击两次才能关闭菜单。

I also tried to close the menu dynamically when app returns to active state by running dismissMenuAnimated on UIDocumentInteractionController instance but it does not work in this case, it does however dismiss the dialog if no interaction was made on it and the method is called.我还尝试在应用程序返回到活动状态时通过在 UIDocumentInteractionController 实例上运行dismissMenuAnimated来动态关闭菜单,但在这种情况下它不起作用,但是如果没有对其进行交互并且调用该方法,它会关闭对话框。

One note, this issue is only present on never iOS version 13+.需要注意的是,此问题仅在从未出现过的 iOS 13+ 版本上出现。 On older OS the menu is closed after interaction as expected.在较旧的操作系统上,菜单在交互后按预期关闭。

We tried using this code other than all react-native stuff we tried:我们尝试使用此代码而不是我们尝试过的所有 react-native 代码:

    @property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController;
@property (atomic) CGRect rect;

RCT_EXPORT_METHOD(openDocumentInteractionControllerWithFileURL:(NSURL *)fileURL){
    if (!fileURL) {
        // Return NO because there was no valid fileURL.
        return;
    }

    UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];

    // Open "Open in"-menu
    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    self.documentInteractionController.delegate = self;

    BOOL sucess; // Sucess is true if it was possible to open the controller and there are apps available

    sucess = [self.documentInteractionController presentOpenInMenuFromRect:self.rect inView:rootCtrl.view animated:YES];


    if(!sucess){
        // Inform app that the activity has finished
        // Return NO because the service was canceled and did not finish because of an error.
        // http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActivity_Class/Reference/Reference.html
    }
}

RCT_EXPORT_METHOD(dismissDocumentInteractionController){
    // Hide menu
    [self.documentInteractionController dismissMenuAnimated:YES];
}

But without success.但没有成功。

You need to close the interaction controller menu after user performs his selection in this menu.用户在此菜单中进行选择后,您需要关闭交互controller菜单。

You can do it in UIDocumentInteractionControllerDelegate like this:你可以在UIDocumentInteractionControllerDelegate这样做:

   - (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {

    [self.documentInteractionController dismissMenuAnimated:YES];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM