SLComposeViewController on Twitter: how to detect duplicate post - twitter

I'm using Social Framework on iOS 6 for Twitter integration, using the following code :
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
// cancelled
} else if (result == SLComposeViewControllerResultDone) {
// done
} else {
// unknown
}
[controller dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:controller animated:YES completion:Nil];
If the user set the same tweet message as one of its old message, I get a popup "The tweet "xxx" is a duplicate and cannot be sent." but the completion handler result value is still SLComposeViewControllerResultDone. Is there a way to know if a tweet has really be sent ?
It seems that the same behaviour is happening for TWTweetComposeViewController.

In iOS 5 twitter integration,
TWTweetComposeViewControllerResult just has 2 options
When user selects done -- TWTweetComposeViewControllerResultDone
When user selects cancel -- TWTweetComposeViewControllerResultCancel
This result doesn't depend on the tweets updated by apple in background. If the tweets fail while updating it shows an alert.
SO i suggest do not implement any custom pop-up for success or failure. As apple itself implemented indications for success/failure tweet updates. On success it plays a sound & on failure a pop-up with reason.

Related

How to change the shared message on Twitter/Facebook in GameCenter

The following is my implemented GameCenter Leaderboards code...
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
LBs.hidden=NO;
}
else {
}
if ([GKLocalPlayer localPlayer].authenticated) {
GameCenter = YES;
}
else {
GameCenter = NO;
}
};
The above code is nothing special, it only lets you open up Game Center and check leaderboards. Then when you click on YOUR score and then SHARE button, it sends it to Twitter (for example). The message on Twitter is "Check Out my score on HighScore playing JungleJim".
However, I want a custom message that includes the HighScore number of the player. How do I change that Shared button to include a custom message on Twitter/Facebook accounts. I don't mean for the user to type up the message. I mean for the message to pop up already there with the highscore number.
Do I have to include code in the above code or somewhere else completely?
I am unfamiliar with game-center-leaderboard, but as for sharing on facebook with the FB iOS SDK, most likely what is implemented in the backend is a share dialog (https://developers.facebook.com/docs/sharing/ios#share_dialog). This as you can see doesn't allow, as CBroe suggested, for pre-populated text in the SDK's UI.
That being said, if there's a way in game-center-leaderboard to override this behavior and share using open graph stories, you could achieve a custom text like: Chris scored a high score using myApp
https://developers.facebook.com/docs/sharing/ios#open_graph

Is it possible to have a Twitter / Facebook share button in a sprite-kit game?

I'm completely lost, all the tutorials I've found have been for iOS 6 apps with Storyboards. My question is if you can have a twitter or facebook sharing feature in a sprite-kit game? If so what is the best way to go about adding it? Alot of the tutorials I've read over use viewcontrollers but sprite-kit uses scenes so I'm a bit confused.
Thanks.
Here is an answer for twitter. Your Welcome!
1) import the Social framework under the Build Phases tab then Link Binary with Libraries. Put this code at the top of your SKScene that you want to share it in.
#import <Social/Social.h>
2) add your tweet button in the -(id)initWithSize:(CGSize)size method with this code:
SKSpriteNode *tweetButton = [SKSpriteNode spriteNodeWithImageNamed:#"share"];
tweetButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-150);
tweetButton.name = #"tweet";
[self addChild:tweetButton];
3) in your touchesBegan: method put the following code to handle clicking the tweet button and composing a tweet
if ([node.name isEqualToString:#"tweet"]) {
// 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 required 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;
}
};
// Set the initial body of the Tweet
[tweetSheet setInitialText:#"This is my tweet text!"];
// Adds an image to the Tweet. Image named image.png
if (![tweetSheet addImage:[UIImage imageNamed:#"image.png"]]) {
NSLog(#"Error: Unable to add image");
}
// Add an URL to the Tweet. You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:#"http://twitter.com/"]]){
NSLog(#"Error: Unable to URL");
}
UIViewController *controller = self.view.window.rootViewController;
[controller presentViewController:tweetSheet animated: YES completion:nil];
}
This may help. ShareKit
It is an easy way to integrate Facebook, Twitter, and other social networking services into your app.

Xcode 5 Facebook post with Links immediately opens the link

I must be missing something obvious here... In the past, I've used the following code to post a message to Facebook from my app. The URL assigned via the addURL call in the past has shown up as the URL for the header of the post in Facebook. In the case of the code below, that would provide a link to the app in the app store.
However in Xcode 5, when I try the same thing, it opens the post dialog, then immediately opens whatever is in passed in as the URL. In this case that means it kicks out of my app and into the App Store. The App Store then helpfully informs the user that they've already installed my app... If I then go back to the app, the post dialog is still open, and you can continue posting... but of course kicking the user out in the first place is not exactly what is intended here...
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) //check if Facebook Account is linked
{
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social plattform to use it, e.g. facebook or twitter
NSString *body = #"";
for (SpelledWord *thisWord in wordList) {
body = [NSString stringWithFormat:#"%#%#\n", body, thisWord.word];
}
if ([[GameState sharedGameState] gameRunState] == kUserPaused) {
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"I'm Playing String Theory: a Word Game\n\nWord List so Far:\n%#",body]]; //the message you want to post
} else {
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"I just played String Theory: a Word Game and got a score of %i\n\nFinal Word List:\n%#",[GameState sharedGameState].score,body]]; //the message you want to post
}
[mySLComposerSheet addURL:[NSURL URLWithString:deepLinkStoreBitly]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}

Display Facebook Compose View after Twitter Compose View on iOS

I have an app where the user can choose to share an update with people via Twitter and Facebook, if they wish to share via both then things are tricky. If you try and call their SLComposeViewController one after the other only Twitter appears and Facebook never appears at all. I have tried to get around this by using NSNotifications but they never seem to be called, and by using completion handlers but those never seem to work and just make the whole UI go bizarre. Can anyone help me on how I would go about displaying am SLComposeView one after the other? I've been banging my head against the wall for four hours.
Assuming that you were trying to use presentViewController's completion handler and getting incorrect results, here's an alternative way. You can present the first composer as you normally would, but then in the composer's completion block, present a second composer. This completion handler is called as soon as the first composer is done being dismissed.
In the example I've set up below, the second composer will only be presented if the first returns SLComposeViewControllerResultDone, allowing you to close out all together in the event that the user hits cancel. However, if you don't want this functionality it can be removed painlessly by keeping the logic for presenting the second composer, but removing the switch statement all together. This code is tested and should produce the results you're looking for. Hope it helps!
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookComposer setInitialText:#"facebook"];
[facebookComposer setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled, bail out");
break;
case SLComposeViewControllerResultDone:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *twitterComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterComposer setInitialText:#"twitter"];
[twitterComposer setCompletionHandler:^(SLComposeViewControllerResult result) {
NSLog(#"done with both sharing options");
}];
[self presentViewController:twitterComposer animated:YES completion:nil];
}
break;
default:
break;
}
}];
[self presentViewController:facebookComposer animated:YES completion:nil];
}

Does the Twitter iOS API provide any way of determining if the tweet was successful?

I'm using the following snippet of code to make a tweet in my iOS 5 application :
- (IBAction)postToTwitterClicked:(id)sender
{
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc]init];
[tweetSheet setInitialText:#"Some sample message here"];
[tweetSheet addURL:[NSURL URLWithString:#"http://myURL"]];
[self presentModalViewController:tweetSheet animated:YES];
}
else
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Unable to tweet"
message:#"Please ensure that you have at least one twitter account setup and have internet connectivity. You can setup a twitter account in the iOS Settings > Twitter > login."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[av show];
}
}
This works fine, but how do I know that the user did actually post a tweet, or if there was a problem?
Since this doesn't implement a delegate, there are no "onError" methods that I can override.
I want to know if the user did successfully post a tweet, so I can action some behaviour such as
Disable a button so they can't do it again
Notify them the post was successful and will show up in their feed shortly
There is no way in the iOS Twitter API that you can see that a Tweet actually was posted on the server. But you can analyze the TWTweetComposeViewControllerResult to see if the tweet was finished composing successfully or if the tweet was cancelled.
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
if (res == TWTweetComposeViewControllerResultDone) {
// Composed
} else if (res == TWTweetComposeViewControllerResultCancelled) {
// Cancelled
}
[self dismissModalViewControllerAnimated:YES];
};
Well, actually, you only can set a handler to call when the user is done composing the tweet: TWTweetComposeViewControllerCompletionHandler. This handler has a single parameter that indicates whether the user finished or cancelled composing the tweet.
You can try to send a tweet and make it fail to check the result code (luckily it's cancelled?).
Another alternative to achieve the desired behaviour is use another API.

Resources