iOS SLComposeViewController - url not displaying for twitter post
Asked Answered
P

5

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];
Parker answered 11/9, 2013 at 14:44 Comment(2)
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.Klenk
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]];Frutescent
R
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.

Rabato answered 13/9, 2013 at 23:12 Comment(0)
A
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.

Avon answered 15/9, 2013 at 12:57 Comment(0)
C
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.

Carrew answered 19/9, 2013 at 6:7 Comment(0)
C
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
}
Callicrates answered 20/9, 2013 at 13:50 Comment(0)
T
0

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

Teets answered 30/1, 2016 at 6:54 Comment(1)
This should be a commentDasi

© 2022 - 2024 — McMap. All rights reserved.