Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect dismissal of UIActivityViewController

I need to present a view, after UIActivityViewController will move to parent VC

...
UIActivityViewController *avvc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
[self presentViewController:avvc animated:YES completion:nil];
like image 400
sedq Avatar asked Jul 11 '16 05:07

sedq


4 Answers

I just want to clarify that the boolean value completed represents the completion state of the individual UIActivity. If the UIActivityViewController is dismissed without any action, the value for activityType will be nil and the value of completed will be false.

[avvc setCompletionWithItemsHandler:^(UIActivityType _Nullable activityType, BOOL completed,
                                      NSArray * _Nullable returnedItems,
                                      NSError * _Nullable activityError) {

    if (activityType == nil)    {
        NSLog(@"UIActivityViewController dismissed without any action.");
    } else {
        NSLog(@"completionWithItemsHandler, activityType: %@, completed: %d, returnedItems: %@, activityError: %@",
         activityType, completed, returnedItems, activityError);
    }
}];
like image 181
Bijoy Thangaraj Avatar answered Oct 24 '22 21:10

Bijoy Thangaraj


Swift 3 Version

avvc.completionWithItemsHandler = { (activityType, completed:Bool, returnedItems:[Any]?, error: Error?) in
   if completed {
      // Do something 
   }
}
like image 21
javal88 Avatar answered Oct 28 '22 05:10

javal88


[avvc setCompletionHandler:^(NSString *activityType, BOOL completed) {
    NSLog(@"after dismiss");
    //Present another VC
}];

Hope this help you.

like image 13
Chandan Avatar answered Oct 28 '22 04:10

Chandan


Xamarin / C#

avvc.CompletionWithItemsHandler = MyCompletionWithItemsHandler;

// ...

void MyCompletionWithItemsHandler(NSString activityType, bool completed, NSExtensionItem[] returnedItems, NSError error)
{
    if (completed)
    {
        // Did not tap Cancel
    } 
    else
    {
        // Cancel was tapped
    }
}
like image 5
Mark Moeykens Avatar answered Oct 28 '22 05:10

Mark Moeykens