Question

I am using the SLComposeViewController to post to twitter and Facebook. I have the same code for both twitter & facebook but the URL is not showing up in the twitter post. How do I fix this?

enter image description here

Twitter code -

socialController = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeTwitter];
[socialController setInitialText:@"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:@"image.jpg"]];
[socialController addURL:[NSURL URLWithString:@"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];

Facebook code -

socialController = [SLComposeViewController
    composeViewControllerForServiceType:SLServiceTypeFacebook];
[socialController setInitialText:@"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:@"image.jpg"]];
[socialController addURL:[NSURL URLWithString:@"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];
Was it helpful?

Solution

SLComposeViewController shows the URL as an attachment on tweet compose view. When it is sent, URL will be appended to the end of the post. You may even add multiple URLs, they will be still shown as attachments. So this is the way it should be, there is nothing to fix.

OTHER TIPS

  • I suggest you actually send the tweet, and check on your Twitter account wether it is really missing the URL or not (it may just be working as expected)

  • This is apparently not what's causing your troubles, but beware of your message length: I have found out that when the text message is too long, the Twitter API silently skips the steps where it should include the shortened URLs for the image and the URL. According to this answer, your text should not exceed 113 characters if you use addURL twice.

i suggest to refer this link.. debug your code and there is one method - (BOOL)addURL:(NSURL *)url that Returns a Boolean value indicating whether the URL was successfully added.

The SLComposeViewController -addURL: method returns a BOOL to indicate if the URL you are trying to attach fits in the character space remaining. Modify your code to check if that is actually returning NO:

BOOL urlOK = [socialController addURL:[NSURL URLWithString:@"http://www.google.com"]];
if(!urlOK) {
 //Notify the user, truncate the message, or something else depending on your use case
}

Twitter now limits tweets to 117 characters if you include a link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top