Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 255
Yevgeniy Leychenko Avatar asked Oct 14 '14 09:10

Yevgeniy Leychenko


1 Answers

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

like image 95
Sergey Topal Avatar answered Sep 21 '22 21:09

Sergey Topal