I'm using Social framework in my project (iOS6), so user can make posts on Facebook or Twitter.

My question is, if there is a way to find out if user have sent a post to social network or he have canceled it and haven't published anything?

I use this code to share posts on 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?
    }
}

Does somebody know the trick? Thanks in advance.

有帮助吗?

解决方案

You can set the completion handler for your compose view controller. There you will get the result SLComposeViewControllerResultDone or SLComposeViewControllerCancelled

  __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];
     }];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top