检测UIActivityViewController的解雇

时间:2016-07-11 05:38:24

标签: ios objective-c xcode

在UIActivityViewController移动到父VC后,我需要提供一个视图

...
UIActivityViewController *avvc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
[self presentViewController:avvc animated:YES completion:nil];

4 个答案:

答案 0 :(得分:17)

Swift 3版本

avvc.completionWithItemsHandler = { (activityType, completed:Bool, returnedItems:[Any]?, error: Error?) in
   if completed {
      // Do something 
   }
}

答案 1 :(得分:11)

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

希望这对你有所帮助。

答案 2 :(得分:3)

我只想澄清一下,布尔值completed代表单个UIActivity的完成状态。如果UIActivityViewController被撤消而没有采取任何措施,则activityType的值为nil,完成的值为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);
    }
}];

答案 3 :(得分:2)

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
    }
}