應用中用到 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’參數來判斷是否完成。