2 u010025993 u010025993 于 2013.04.26 09:54 提问

苹果的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或者邮件发送成功之后。

应该怎么做?

1个回答

Mr_me
Mr_me   2013.04.26 11:25
已采纳
[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’参数来判断是否完成。

Axing1991
Axing1991 进不来这个block会是什么原因呢
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!