ios 8 completion block not called
Asked Answered
F

1

8

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.

Footplate answered 14/10, 2014 at 9:10 Comment(0)
S
5

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).

Sumption answered 5/3, 2015 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.