I have a NSString which one I use for share on Facebook & Twitter. My requirement is that text will be a link after share on Facebook. On Facebook when user click on that text, then direct go to that link.
My code is like below:
NSInteger Score = [[NSUserDefaults standardUserDefaults] integerForKey:#"K_ScoreVal"];
SLComposeViewController *Facebooksheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[Facebooksheet setInitialText:[NSString stringWithFormat:#"I just completed level 1.1 and score is %d points.",Score]];
[[CCDirector sharedDirector] presentViewController:Facebooksheet animated:YES completion:nil];
I just completed level 1.1 and score is 455 points. This is my text, which one I share on Facebook. But when user click on this text, then direct go to a link. Meanwhile I want to make this text as a hyperlink.
Please suggest me.
What you really want to use is the OpenGraph API for games. Have a look at the introduction docs at https://developers.facebook.com/docs/games/opengraph/
If you go down this road, you can use the
Achievements API
Scores API
Have you tried using Attributed Strings?
NSString *shareString = [[NSAttributedString alloc] initWithString:#"I just completed level 1.1 and score is 455 points." attributes:#{NSLinkAttributeName: #"http://yourlink.com"}];
Related
I had implemented pinterest sharing code in my app as well. Its working fine. But problem arrives at one scenario see follow
Correct working:
[pinterest createPinWithImageURL:[NSURL URLWithString:imageUrl]
sourceURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",shareUrl]]
description:#"My Description"];
Then it will share Pinterest Description same My Description as per my expectation.
But when I send Description Test like :
[pinterest createPinWithImageURL:[NSURL URLWithString:imageUrl]
sourceURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",shareUrl]]
description:#"My Details & Description"];
Then it will share Pinterest Description like My Details.
My expected text here is My Details & Description this is trunks my string after & symbol.
What actually wrong happening with me please look at here.
AFAIK, Pinterest's Pin It SDK isn't open source, so it's difficult to find out what's really going on.
I would guess, however, that this method is creating a GET request under-the-hood that's incorrectly URL encoding the description parameter (perhaps they're using stringByAddingPercentEscapesUsingEncoding or some other naive method).
I'd recommend contacting the Pinterest SDK developers/maintainers to look into this.
As a quick fix, you might try URL encoding the & yourself. For example, you might try replacing & with %26, e.g.
NSString *description = // ...whatever it should be set to...
description = [description stringByReplacingOccurrencesOfString:#"&" withString:#"%26"];
However, this might actually lead to other problems as the Pinterest SDK is likely doing some sort of URL encoding and would likely encode the % symbol.
Another naive approach may simply be to replace & with the word and, such as
NSString *description = // ...whatever it should be set to...
description = [description stringByReplacingOccurrencesOfString:#"&" withString:#"and"];
Again, it's hacky, but it's a workaround for a bug that's likely in the underlying SDK.
Is there already a way to share the picture and the text from my app to whatsapp in one motion?
I can only find a android solution. It must be possible with iOS? Hope anybody has got the solution!
I found the solution for both picture and text over here, but Im looking for the option which android yet provides; from my app, in one motion, send a picture and text to a whatsapp contact.
Help is very much needed, tried everything and searched everywhere! Will the expert please stand up :)! Thanks in advance, hope to hear from you!
WhatsApp has a "Custom URL Scheme" and "Document Interaction" (http://www.whatsapp.com/faq/en/iphone/23559013).
But it looks like it does not support annotions for setting the text like Instagram (http://instagram.com/developer/mobile-sharing/iphone-hooks/)
This is the way to share but WITHOUT text.
self.documentationInteractionController =[UIDocumentInteractionController interactionControllerWithURL:jpegFileURL];
self.documentationInteractionController.delegate = self;
self.documentationInteractionController.UTI = #"public.jpeg";
self.documentationInteractionController.UTI = #"net.whatsapp.image";
// NOT WORKING - Found this solution, no success
self.documentationInteractionController.annotation = #{#"message":#"Text here",#"text":#"Text here"};
// NOT WORKING - Found other solution, no success
self.documentationInteractionController.annotation = [NSString stringWithFormat:#"text=Text here"];
// WORKING - BUT only for instagram
self.documentationInteractionController.annotation = #{#"InstagramCaption":#"Text here"};
[self.documentationInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
Hope someone has the complete answer to the question, i am also stuck with the image and text combo.
I'm trying to post an article title and an article URL to twitter and then append the app's name to the end of the tweet. So something like
"How to grow a cactus (via #appname)" attached URL
I was having trouble figuring out how to balance the length of the title and URL to make sure that the tweet doesn't exceed 140 characters. So if the URL is really long, cut some of the article title off so it can be under 140 characters.
Looking at Twitter's guidelines for SLComposeViewController they state this part:
Note that the methods for setting initial content respond with Boolean values; this allows you, the developer, to not have to worry about the current count of characters in the body of the Tweet that you are initializing. If the method returns YES, there was enough room to add the content. If the method returns NO, the content you attempted to add would result in a Tweet longer than 140 characters. The logic for character counting also takes into effect the current number of characters required for t.co URL wrapping.
(From the "Code Example" section.)
Given that, I wrote the following code to build a tweet and balance the URL length and article length:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterViewController addURL:[NSURL URLWithString:self.article.url]];
NSString *titleToShare = self.article.title;
while ([twitterViewController setInitialText:[NSString stringWithFormat:#"%# (via #SyllableApp)", titleToShare]]) {
titleToShare = [titleToShare substringToIndex:titleToShare.length - 1];
}
[self presentViewController:twitterViewController animated:YES completion:nil];
}
Which basically adds the URL then constructs the rest of the tweet by looping through the setInitialText: method until it returns YES, decreasing the length of the title by 1 each time it returns NO in order to get closer to the required length.
But it never returns YES! Even when I know it should. I was using one article where it could potentially exceed 140 characters as the title is 105 characters long and the URL is 55, plus the app credit. So it should theoretically be able to shorten the title down and then add it fine, but it never happens.
So what's going on? How do I accomplish link attachment with SLComposeViewController?
while ([twitterViewController setInitialText:[NSString stringWithFormat:#"%# (via #SyllableApp)", titleToShare]])
=>
while (![twitterViewController setInitialText:[NSString stringWithFormat:#"%# (via #SyllableApp)", titleToShare]])
There is a ! missing in condition, so you shorten the post when it fits, not when it is too long ;)
The problem with this approach is that it works only on iOS6.
SLComposeViewController *social = [[SLComposeViewController alloc] init];
NSString *stringToShare = #"";
for (int i = 0; i < 150; i++)
{
stringToShare = [stringToShare stringByAppendingString:#"x"];
}
NSLog(#"%#",[social setInitialText:stringToShare]?#"YES":#"NO");
yields different results on iOS6 (NO) and iOS7 (YES). The answer to this behaviour comes from the documentation of SLComposeViewController
// Sets the initial text to be posted. Returns NO if the sheet has already been
// presented to the user. On iOS 6.x, this returns NO if the specified text
// will not fit within the character space currently available; on iOS 7.0 and
// later, you may supply text with a length greater than the service supports,
// and the sheet will allow the user to edit it accordingly.
- (BOOL)setInitialText:(NSString *)text;
Probably is worth either having different approaches on iOS6 and 7, or check the length without using SLComposeViewController method.
As imihaly said, you did miss a "!".
And 140 characters count is the limit of title only, not including URL.So your title is 105 characters long which is less than 140,this method should return YES.
There is an open bug with link lengths not getting calculated correctly (radar://10469407). This might be related. You might try sending a Tweet with a link in it to check which URL shortener is being used (I imagine it's using t.co, but I could be wrong).
I successfully integrated Facebook SDK 3.1 in my app, and I'm trying to propose iOS6+ only features to iOS6+ users. I was able to show the share sheet, but I was quite disapointed when I saw what the post on my wall looked like. Here is an image to describe what I mean :
The first one is what is got from a pre-iOS6 dialog (the web popup), and the second one is got from the new iOS6+ Native Facebook Dialog (SLComposeViewController, in other words).
My questions are :
Is there a way to make the second post look like the first one using FacebookNativeDialog ? Is it possible to give a params Dictionary like before so the post will display correctly "via {myAppName}" ? Or is it simply the new way of showing posts, and the older way is deprecated ?
Two things:
1/ "via iOS" attribution - This is currently per design and cannot be customized for your app.
2/ Having the same look - you can get this by providing only the link when setting up the composer (i.e. don't provide the image):
SLComposeViewController *fbVC = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbVC setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Canceled");
} else if (result == SLComposeViewControllerResultDone) {
NSLog(#"Posted");
}
}];
[fbVC addURL:[NSURL URLWithString:#"https://developers.facebook.com/ios"]];
[self presentViewController:fbVC animated:YES completion:nil];
The key to getting the same look is that the page linked to has Open Graph tags that Facebook can recognize to properly display the data. You can test if the OG tags are good by entering the link into https://developers.facebook.com/tools/debug
If the page does not have OG tags, the link will simply be displayed.
I'm trying to integrate ChartBoost in my app and single ads are displaying OK.
This is the initial setup:
ChartBoost *cb = [ChartBoost sharedChartBoost];
cb.delegate = self;
cb.appId = CHARBOOST_APP_ID;
cb.appSignature = CHARBOOST_APP_SIGNATURE;
[cb showInterstitial];
But when I'm trying to display the "More apps" page, using the ChartBoost tutorial, I don't get the response.
-(IBAction) switchToMoreGames: (id) sender{
ChartBoost* cb = [ChartBoost sharedChartBoost];
cb.delegate = self;
[cb cacheMoreApps];
[cb showMoreApps];
}
I'd be very appreciative for any kind of help I can get, thanks in advance!
Since there were many requests for me to answer my own question rather than update it, I have created this answer.
To add "More apps" page you have to go to "Edit your app", then click "More apps page" tab and type the name of your campaign in the input field of the iPhone, which is showing on the right.