如何检测已选择的活动以及如何检查邮件是否已发送?

时间:2013-06-03 18:09:36

标签: ios cocoa touch share uiactivityviewcontroller

我已经有了从app上简单分享一些消息的代码。

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

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

问题:

  1. 可以检测选择了哪个共享选项?
  2. 可以检测邮件是否已被共享或取消?
  3. 提前谢谢。

3 个答案:

答案 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);
};