I'm presenting iOS Twitter share sheets (SLComposeViewController
on iOS 6, TWTweetComposeViewController
on iOS 5) in my app with user-selected text and a link. If the text is too long, I truncate it:
NSString *text = [self getSelectedText];
NSString *myLink = [self getLink];
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller addURL:[NSURL urlWithString:myLink]];
while (![controller setInitialText:text] && text.length > 10)
{
text = [text substringToIndex:text.length - 5];
}
[self presentViewController:controller animated:YES completion:NULL];
When I do this, the character count gets messed up. setInitialText
returns YES
before I'm down to the expected length, and the share sheet comes up showing overflow text. For example, if the link is 35 characters long, the share sheet accepts a string of length 117 after decrementing a couple of times. 117 + 35 = 152 (12 over), but the share sheet shows 9 over.
Am I using this API wrong, or is there a bug in the character counts? This article on Twitter's dev site seems to suggest there's an issue, but it's over a year old.
EDIT: The result is the same if I append the link to the end of the text manually instead of using the addURL
method.