简体   繁体   中英

ios 8 completion block not called

In my app I am using TTOpenInAppActivity to insert "Open in" action inside UIActivityController. Inside it works like this:

Some view controller presents UIActivityController with TTOpenInActivity already built in.

-(void)openWithAction
{
    NSURL *fileURL = SOME_URL;
    CGRect rect = SOME_RECT;
    TTOpenInAppActivity *openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.view andRect:rect];
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[fileURL] applicationActivities:@[openInAppActivity]];

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        // Store reference to superview (UIActionSheet) to allow dismissal
        openInAppActivity.superViewController = activityViewController;
        // Show UIActivityViewController
        [self presentViewController:activityViewController animated:YES completion:NULL];
    } else {
        // code for iPad, irrelevant
    }
}

When user taps "Open in" button, the following method is triggered:

- (void)performActivity
{
    if(!self.superViewController){
        [self activityDidFinish:YES];
        return;
    }

    // Dismiss activity view
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        // iPhone dismiss UIActivityViewController
        [self.superViewController dismissViewControllerAnimated:YES completion:^(void){

            if (self.fileURLs.count > 1) {
                [self openSelectFileActionSheet];
            }
            else {
                // Open UIDocumentInteractionController
                [self openDocumentInteractionControllerWithFileURL:self.fileURLs.lastObject];
            }
        }];
    } else {
        // code for iPad, irrelevant
        }
    }
}

As the app is for iPhone only, this piece of code should be executed:

[self.superViewController dismissViewControllerAnimated:YES completion:^(void){

                if (self.fileURLs.count > 1) {
                    [self openSelectFileActionSheet];
                }
                else {
                    // Open UIDocumentInteractionController
                    [self openDocumentInteractionControllerWithFileURL:self.fileURLs.lastObject];
                }
}];

In iOS7 everything works fine. In iOS8 UIActivityController is dismissed and then nothing happens. While debugging I did manage to detect that in iOS8 completion handler is never called.

Please, help me find out the reason for this behavior and make it work as it should.

Thank you in advance.

In iOS 8, when you tap on "Open in", UIActivityViewController is dismissed automatically. So, when you call self.superViewController dismissViewControllerAnimated:completion: , viewController was already dismissed and method do nothing (so completion not called).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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