8

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];
Amar
  • 13,202
  • 7
  • 53
  • 71
rohan_vg
  • 1,087
  • 3
  • 15
  • 27
  • 1
    Pretty sure that's just how it works. The little paperclip you see on the Tweet dialog means that there's a link attached. Facebook does not have an API for you to upload an image AND share a link at the same time, so the link has to go inside the message body instead. – Ming Li Sep 11 '13 at 15:54
  • I didn't use addURL yet but this could help you: try to add the link to the initialText if you want to see it in the tweet text: [socialController setInitialText:[NSString stringWithFormat: @"Testing: This is the app link! %@", tweetURL]]; – Sawsan Sep 15 '13 at 14:20

5 Answers5

15

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.

mkubilayk
  • 2,477
  • 3
  • 20
  • 27
1
  • 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.

Community
  • 1
  • 1
Sébastien
  • 13,831
  • 10
  • 55
  • 70
1

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.

Jignesh B
  • 490
  • 7
  • 18
0

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
}
RyanR
  • 7,728
  • 1
  • 25
  • 39
0

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

Vijay Rathod
  • 197
  • 1
  • 3
  • 11