IOS SLComposeViewController - URL not showing for Twitter message

I use SLComposeViewController to post to Twitter and Facebook. I have the same code for twitter and facebook, but the URL does not appear in the Twitter message. How to fix it?

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]; 
+8
ios iphone facebook twitter slcomposeviewcontroller
source share
5 answers

SLComposeViewController shows the URL as an attachment in the form of a tweet view. When it is sent, the URL will be added to the end of the message. You can even add multiple URLs, they will appear as attachments. So this is how it should be, nothing can be fixed.

+15
source share
  • I suggest you send a tweet and check your Twitter account, as the URL is actually missing or not (it may work as expected)

  • This doesn't seem to be causing the problems, but beware of the length of your post: I found out that when the text message is too long, the Twitter API silently skips steps in which it should include shortened URLs for the image and URL addresses. According to this answer, your text should not exceed 113 characters if you use addURL twice.

+1
source share

I suggest referring to this link .. to debug your code and there is one method - (BOOL)addURL:(NSURL *)url , which returns a boolean value indicating whether the URL was successfully added.

+1
source share

The SLComposeViewController -addURL: method returns BOOL to indicate whether the URL you are trying to attach matches in the remaining character space. Modify your code to check if this really returns 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 } 
0
source share

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

0
source share

All Articles