I am currently using SLComposeViewController to post a user's score to twitter or facebook (depending on the button they tap). When they share, they are rewarded with virtual currency. The problem that I'm facing is that it will only tell me whether a user hit Send or Cancel. How can I check if the tweet is actually posted to twitter? This will help combat cases where a user attempts to submit the same tweet twice (which twitter doesn't allow).
This is my code for now:
//Check if user can send tweet
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
switch(result) {
//This means the user cancelled without sending the Tweet
case SLComposeViewControllerResultCancelled:
NSLog(@"User Canceled");
break;
//This means the user hit 'Send'
case SLComposeViewControllerResultDone:
NSLog(@"User Tapped Send");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
//Show alert & reward user here
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:NO completion:^{
NSLog(@"Tweet Sheet has been dismissed.");
}];
});
};
[tweetSheet setInitialText:[NSString stringWithFormat:@"Just scored %ld %@! I challenge anyone to try & beat it! 😎🌲", (long)scene.score, suffix]];
[tweetSheet addURL:[NSURL URLWithString:@"http://appstore.com/appurlhere"]];
[self presentViewController:tweetSheet animated:YES completion:^{
NSLog(@"Tweet sheet has been presented.");
}];
}
else {
//Something went wrong, aka no network connection
};
How can I check if the tweet was actually posted (Using the Social Framework).
This question is a year old but I just happened upon it and had just figured out (only a few minutes ago!) an answer that works in my project. In my project, I am counting how many tweets were sent to verify that the user tapped send. If the user cancels the tweet, the count does not increase. Hopefully this will help someone out. Call [self tweetSuccessful] under SLComposeViewControllerResultDone. Not sure if this is the "right" way but it seems to be accurate.
-(void)twitterImageTouched:(UIGestureRecognizer *)gesture
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"Test";
[tweetSheet addImage:[UIImage imageNamed:@"yourImageName"];
[tweetSheet addURL:[NSURL URLWithString:@"http://yourURL"]];
[self presentViewController:tweetSheet animated:YES completion:nil];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result)
{
switch (result)
{
case SLComposeViewControllerResultCancelled:
NSLog(@"tweet cancelled");
break;
case SLComposeViewControllerResultDone:
NSLog(@"tweet completed");
[self tweetSuccessful];
break;
default:
break;
}
};
}
NSLog(@"Twitter Button Pressed.");
}
-(void)tweetSuccessful
{
NSInteger i = [[NSUserDefaults standardUserDefaults] integerForKey:@"numberOfTweets"];
[[NSUserDefaults standardUserDefaults] setInteger:i + 1 forKey:@"numberOfTweets"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"%li tweets have been shared", (long)i + 1);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With