如果用户按下取消,UIActivityViewController完成处理程序仍会调用操作

Col*_*lin 7 ios completionhandler uiactivityviewcontroller

在我的UIActivityViewController中,我使用完成处理程序来执行"成功共享"通知.它可以工作,但我唯一的问题是,如果用户按下取消,它仍会显示通知.

这是我的完成处理程序代码,

[controller setCompletionHandler:^(NSString *activityType, BOOL completed) {


    CWStatusBarNotification *notification = [CWStatusBarNotification new];
    [notification displayNotificationWithMessage:@"? Successfully Shared Centre!"
                                          forDuration:3.0f];

    notification.notificationLabelBackgroundColor = [UIColor colorWithRed:38.0f/255.0f green:81.0f/255.0f blue:123.0f/255.0f alpha:1.0f];
    notification.notificationLabelTextColor = [UIColor whiteColor];



}];
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

Jya*_*aif 19

注意:在iOS8中不推荐使用completionHandler属性,因此不可能再知道共享操作的结果. https://developer.apple.com/documentation/uikit/uiactivityviewcontroller/1622010-completionhandler

更新:就像adruzh所说,在iOS8上有一个新的completionHandler,Apple在文档中忘了提及:

[activityController setCompletionWithItemsHandler:
    ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
}];
Run Code Online (Sandbox Code Playgroud)

https://developer.apple.com/documentation/uikit/uiactivityviewcontroller/1622022-completionwithitemshandler

  • 看起来像文档中的错误 - 有一个新的处理程序,它在UIKit更改中被引用 (2认同)

Nic*_*rge 13

这就是completed争论的结果:

[controller setCompletionHandler:^(NSString *activityType, BOOL completed) {
    if (!completed) return;

    CWStatusBarNotification *notification = [CWStatusBarNotification new];
    [notification displayNotificationWithMessage:@"? Successfully Shared Centre!"
                                     forDuration:3.0f];

    notification.notificationLabelBackgroundColor = [UIColor colorWithRed:38.0f/255.0f green:81.0f/255.0f blue:123.0f/255.0f alpha:1.0f];
    notification.notificationLabelTextColor = [UIColor whiteColor];
}];
Run Code Online (Sandbox Code Playgroud)