原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/2248
问题描述:
应用中用到 UIActivityViewController 。
使用代码:
NSString *postText = @"My Text";
NSArray *activityItems = @[postText];
UIActivityViewController *activityController =
[[UIActivityViewController alloc]
initWithActivityItems:activityItems applicationActivities:nil];
activityController.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, nil];
[self presentViewController:activityController
animated:YES completion:nil];
运行正常,从UIActivityViewController打开邮件的时候,也会显示出需要的内容。
现在我要在数据库中执行一些动作,条件是在post或者邮件发送成功之后。
应该怎么做?
解决方案:[activityController setCompletionHandler:^(NSString *act, BOOL done)
{
NSLog(@"act type %@",act);
NSString *ServiceMsg = nil;
if ( [act isEqualToString:UIActivityTypeMail] ) ServiceMsg = @"Mail sent";
if ( [act isEqualToString:UIActivityTypePostToTwitter] ) ServiceMsg = @"Post on twitter, ok!";
if ( [act isEqualToString:UIActivityTypePostToFacebook] ) ServiceMsg = @"Post on facebook, ok!";
if ( done )
{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[Alert show];
[Alert release];
}
else
{
// didn't succeed.
}
}];
用完成处理程序的‘done’参数来判断是否完成。