社交框架 - 如何知道消息是否已发送

时间:2013-06-10 04:24:42

标签: iphone ios objective-c request social-framework

我在我的项目(iOS6)中使用Social framework,因此用户可以在 Facebook Twitter 上发帖。

我的问题是,如果有办法确定用户是否已将帖子发送到社交网络,或者他已取消该帖子并且尚未发布任何内容?

我使用此代码在Twitter上分享帖子:

-(IBAction)askOnTwitter
{   
    if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
    {
        [self showErrorAlert];
        twitterButton.enabled = NO;
        return;
    }

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 
    {
        slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

        [slComposeViewController setInitialText:@"Hey"];

        [self presentViewController:slComposeViewController animated:YES completion:nil];

        // So have user published a post or he haven't? How to know?
    }
}

有人知道这个伎俩吗?提前谢谢。

1 个答案:

答案 0 :(得分:2)

您可以为撰写视图控制器设置完成处理程序。在那里,您将获得结果SLComposeViewControllerResultDoneSLComposeViewControllerCancelled

  __block __weak SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

 [slComposeViewController setCompletionHandler:^
     (SLComposeViewControllerResult result){

      if (result == SLComposeViewControllerResultDone) {
             NSLog(@"Done successfully");
         }
         else{
             NSLog(@"Cancelled");
         }

         [slComposeViewController dismissViewControllerAnimated:YES completion:nil];
     }];