Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController dismiss MailViewController

I've try to send an email over the UIActivityViewController and it works fine, but the mail view is not dismissed after the email was send. It also wont't dismiss when the user has pushed the Cancel button.

What can I do to fix the problem?

Here the code I have used:

//conf share view
    NSString *textToShare = @"Teststring!";
    UIImage *imageToShare = fetchedImage;
    NSURL *urlToShare = [NSURL URLWithString:string_url];
    NSArray *activityItems = [[NSArray alloc]  initWithObjects:textToShare, imageToShare,urlToShare,nil];

    UIActivity *activity = [[UIActivity alloc] init];

    NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
    UIActivityViewController *activityVC =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:applicationActivities];

    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact,
        UIActivityTypePostToWeibo,
        UIActivityTypeCopyToPasteboard,
        UIActivityTypeSaveToCameraRoll,
        UIActivityTypePrint];

    [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
        NSLog(@"CompletionHandler was called!");
    }];

Thanks!

like image 347
blacksheep_2011 Avatar asked Oct 14 '12 12:10

blacksheep_2011


1 Answers

I have the solution. You want to present the UIActivityViewController in your fundamental, i.e. your highest or last view controller. In my case, this worked:

[[[self parentViewController] parentViewController] presentViewController:activityViewController animated:YES completion:nil];

Try out yourself how many times you have to call parentViewController until you are accessing the highest view controller. In my simple MasterView/DetailView app, I had to call it twice.

like image 183
Erik Avatar answered Sep 30 '22 13:09

Erik