I want to setinitialtext in such a way when it's posted to timeline. it should say like below and i want to set a url behind the seen for GlanseApp text only
NSString *KSocialSharingTextFBPT=#" Just discovered this great item via [GlanseApp](https://itunes.apple.com/us/app/glanse/id762075664?mt=8) for iPhone"
how can i achive this ?
Here is the code for sharing
SLComposeViewController *composeController = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[composeController setInitialText:KSocialSharingTextFBPT];
[composeController addImage:image];
[composeController addURL: [NSURL URLWithString:[product objectForKey:#"producturl"]]];
composeController.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;
}
};
iOS does not support rich text (RTF) like MacOS does. The only UI object that supports clickable text links directly is UIWebView.
You can try This link if it helps you.
Related
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.
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];
}
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];
}
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.
Using SLComposeViewController, I notice curious behavior when posting to Facebook if both the image and the URL are present. Specifically, if you have both image and URL, the URL appears in the body of the Facebook post in the view of the SLComposeViewController, immediately after the initialText if I do the following:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSString *text = #"This is a test Facebook post with SLComposeViewController.";
NSURL *url = [NSURL URLWithString:#"http://http://stackoverflow.com/questions/12503287/tutorial-for-slcomposeviewcontroller-sharing"];
UIImage *image = ...;
[controller setInitialText:text];
[controller addURL:url];
[controller addImage:image];
[self presentViewController:controller animated:YES completion:nil];
That's obviously a hassle because the if the URL is long, the initial text is pushed off of the visible portion of the view of SLComposeViewController and I only see the latter portion of the URL:
If I repeat this process, this time not adding the image to the post, the text of the URL conveniently does not show up in the body at all (even though it shows up properly online).
Bottom line, only if there is an image and and URL does the URL show up in the body of the post. And I see this same pattern when I use FBNativeDialogs.
Is there any way to stop that behavior with SLComposeViewController, so that I can have both image and URL connected to the Facebook post without exposing the user to the web site's long, ugly URL? Clearly I can use any of the non-SLComposeViewController solutions (e.g. design my own UI for composing the Facebook post, using Facebook's deprecated Feed Dialog, etc.). Just wondering if I'm overlooking some obvious SLComposeViewController solution.
In the end, I've given up on the SLComposeViewController (as well as the FBNativeDialogs). They present a nice, integrated feel, but given that my posts invariably include both photo and URL, this really doesn't work. On top of that, the posts were not correctly attributed as being from my app.
So, in the end, I've written my own user interface and use the the Facebook SDK 3.1 FBRequestConnection as outlined here. I think it's a little silly that we all have to make our own UI because the weaknesses in the native UI, but it is what it is.
The new dialog seems to be designed around you providing most of the share data as tags on the website the provided link points to. Like this:
Title:
<title>TITLE</title>
Description:
<meta name="description" content="DESCRIPTION">
Image:
<meta property="og:image" content="IMAGE_URL">
App ID:
<meta property="fb:app_id" content="APP_ID">
This way you only need to provide the initial text and an URL. You can look how the official Youtube app does it's Facebook sharing for an example.
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
NSString *format = #"“%#” %# /via #DesignSceneApp";
NSString *message = [NSString stringWithFormat:format, title, url]
NSUInteger idx = title.length;
while (![twitter setInitialText:message]) {
idx -= 5;
if (idx > 5) {
message = [NSString stringWithFormat:format,
[NSString stringWithFormat:#"%#…", [title substringToIndex:idx]],
url
];
} else {
// Give up on the title.
message = [NSString stringWithFormat:#"%# /via #DesignSceneApp", url];
[twitter setInitialText:message];
break;
}
}
[self presentViewController:twitter animated:YES completion:nil];