3

我有代码可以简单地从应用程序中分享一些消息。

UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
                                                    initWithActivityItems:@[message]
                                                    applicationActivities:nil];

activityViewController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityViewController animated:YES completion:nil];

问题:

  1. 是否可以检测到选择了哪个共享选项?
  2. 是否可以检测消息之前是否已共享或取消?

先感谢您。

4

3 回答 3

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];
于 2013-06-03T19:24:06.540 回答
3

在 iOS8 中,completionHandler 属性已被弃用。请改用 completionWithItemsHandler 属性:

activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(@"completed    = '%@'", (completed) ? @"YES" : @"NO");
NSLog(@"activityType = '%@'", activityType);
};
于 2015-01-14T20:39:28.517 回答
2

您需要实现UIActivityViewControllerCompletionHandler,您可以在其中查看用户做了什么或他们是否取消了。

于 2013-06-03T18:50:09.797 回答