7

我尝试通过 UIActivityViewController 发送电子邮件并且它工作正常,但是在发送电子邮件后邮件视图不会被关闭。当用户按下取消按钮时,它也不会关闭。

我能做些什么来解决这个问题?

这是我使用的代码:

//conf share view
    NSString *textToShare = @"Teststring!";
    UIImage *imageToShare = fetchedImage;
    NSURL *urlToShare = [NSURL URLWithString:string_url];
    NSArray *activityItems = [[NSArray alloc]  initWithObjects:textToShare, imageToShare,urlToShare,nil];

    UIActivity *activity = [[UIActivity alloc] init];

    NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
    UIActivityViewController *activityVC =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:applicationActivities];

    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact,
        UIActivityTypePostToWeibo,
        UIActivityTypeCopyToPasteboard,
        UIActivityTypeSaveToCameraRoll,
        UIActivityTypePrint];

    [activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
        NSLog(@"CompletionHandler was called!");
    }];

谢谢!

4

3 回答 3

8

我有解决办法。你想在你的基础中呈现 UIActivityViewController,即你的最高或最后一个视图控制器。就我而言,这有效:

[[[self parentViewController] parentViewController] presentViewController:activityViewController animated:YES completion:nil];

尝试自己调用 parentViewController 多少次,直到您访问最高的视图控制器。在我简单的 MasterView/DetailView 应用程序中,我不得不调用它两次。

于 2012-10-25T01:12:38.547 回答
4

它总是在发布完成后进入这个完成处理程序,不管它成功与否

[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed)
 {
            if (completed)
     {
         UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Posting was successful" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [objalert show];
         objalert = nil;
     }else
     {
         UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Posting was not successful" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [objalert show];
         objalert = nil;
     }
 }];
于 2013-08-29T07:04:53.920 回答
2

然后尝试在 CompletionHandler 上关闭它

[activityVC setCompletionHandler:^(NSString *activityType, BOOL completed) {
       //Dismiss here 
    }];
于 2012-10-14T14:04:46.367 回答