Alessandro
Alessandro

Reputation: 4110

Twitter in ios6 Social framework method complete

I am posting a message to twitter in the following way:

 if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{



//  Create an instance of the Tweet Sheet
SLComposeViewController *tweetSheet = [SLComposeViewController
                                       composeViewControllerForServiceType:
                                       SLServiceTypeTwitter];

// Sets the completion handler.  Note that we don't know which thread the
// block will be called on, so we need to ensure that any UI updates occur
// on the main queue
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
    switch(result) {
            //  This means the user cancelled without sending the Tweet
        case SLComposeViewControllerResultCancelled:
            break;
            //  This means the user hit 'Send'
        case SLComposeViewControllerResultDone:
            break;
    }

    //  dismiss the Tweet Sheet
    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:NO completion:^{
            NSLog(@"Tweet Sheet has been dismissed.");
        }];
    });
};

//  Set the initial body of the Tweet
[tweetSheet setInitialText:@"Download Cleverly at "];

//  Adds an image to the Tweet.  For demo purposes, assume we have an
//  image named 'larry.png' that we wish to attach
if (![tweetSheet addImage:[UIImage imageNamed:@"iTunesArtwork120.png"]]) {
    NSLog(@"Unable to add the image!");
}

//  Add an URL to the Tweet.  You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/cleverly/id703006076?ls=1&mt=8"]]){
    NSLog(@"Unable to add the URL!");
}

//  Presents the Tweet Sheet to the user
[self presentViewController:tweetSheet animated:NO completion:^{
    NSLog(@"Tweet sheet has been presented.");
}];
}
}

I want to run this method:

NSInteger highScore = [[NSUserDefaults standardUserDefaults] integerForKey:@"SharingsLeft"];
if (highScore != 999999999) {
[[NSUserDefaults standardUserDefaults] setInteger:highScore + 5 forKey:@"SharingsLeft"];
[self.SendCounter setTitle:[NSString stringWithFormat:@"%ld", (long)highScore] forState:UIControlStateNormal];

Only when the user has actually posted the tweet. But there is no method in the block that advises me when the tweet has been posted, or when the user has pressed 'post' button.

Upvotes: 0

Views: 354

Answers (2)

donkey
donkey

Reputation: 1448

       tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
                    switch(result) {
                //  This means the user cancelled without sending the Tweet
              case SLComposeViewControllerResultCancelled:
                    break;
             //  This means the user hit 'Send'
            case SLComposeViewControllerResultDone:
                break;
         }

 };

totaly agree with Dante

Upvotes: 0

Shubhank
Shubhank

Reputation: 21805

tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
    switch(result) {
            //  This means the user cancelled without sending the Tweet
        case SLComposeViewControllerResultCancelled:
            break;
            //  This means the user hit 'Send'
        case SLComposeViewControllerResultDone:
            break;
    }

};

If you read correctly SLComposeViewControllerResultDone is when user pressed Send/Post for the sheet , here you can add your method call which you want to call on successful post by user

More info in the doc here

Upvotes: 1

Related Questions