问题描述
- 苹果的UIActivityViewController
- 应用中用到 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’参数来判断是否完成。
时间: 2024-09-21 13:35:35