Question

Example project: http://cl.ly/261z1P100T25

Under iOS 7, when I try to add a URL to a tweet, the method should return NO if there's no enough space to add it ("This method returns NO if url does not fit in the currently available character space") but this method ALWAYS returns YES in iOS 7. For example, in the following example, "Couldn't add." is never printed and the tweet is presented with -32 characters remaining.

SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
NSString *titleToShare = @"i am a string a super string the most super string that ever existed in the world of the super string universe which as it happens is very super as well";

if (titleToShare.length > 140) {
    titleToShare = [titleToShare substringToIndex:140];
}

[twitterViewController setInitialText:titleToShare];

if (![twitterViewController addURL:[NSURL URLWithString:@"http://google.com"]]) {
    NSLog(@"Couldn't add.");
}

[self presentViewController:twitterViewController animated:YES completion:nil];

Is it broken? Do I have to code around this?

Was it helpful?

Solution

It's not broken, just it isn't publicly documented well. I found in code following comment for setInitialText: method:

// 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.

So, they allow you to set text greater then 140 characters, just you can't post this text because post button is disabled.

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