我已经有了从app上简单分享一些消息的代码。
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:@[message]
applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityViewController animated:YES completion:nil];
问题:
提前谢谢。
答案 0 :(得分:6)
以下是如何使用UIActivityViewControllerCompletionHandler
的示例:
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:@[@"abc", someImage]
applicationActivities:nil];
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
NSLog(@"%@, %d", activityType, completed);
}];
activityViewController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityViewController animated:YES completion:nil];
答案 1 :(得分:2)
您需要实施UIActivityViewControllerCompletionHandler
,您可以在其中查看用户做了什么或是否取消了。
答案 2 :(得分:2)
在iOS8中,不推荐使用completionHandler属性。请改用completionWithItemsHandler属性:
activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(@"completed = '%@'", (completed) ? @"YES" : @"NO");
NSLog(@"activityType = '%@'", activityType);
};