I use TWTweetComposeViewController, when available, to send tweets from my iOS application. I pre-populate the view controller with a text template, and then let the user modify and submit as they wish. It works great for the most part. Distilled, it looks like this (with body pointing to a valid NSString ):
if (NSClassFromString(@"TWTweetComposeViewController")) { TWTweetComposeViewController *iOS5twitter = [[TWTweetComposeViewController alloc] init]; [iOS5twitter setInitialText:body]; iOS5twitter.completionHandler = ^(TWTweetComposeViewControllerResult result) { [self.viewController dismissViewControllerAnimated:YES completion:nil]; }; [self.viewController presentViewController:iOS5twitter animated:YES completion:nil]; [iOS5twitter release]; } else { }
Now, if body too long, i.e. more than 140 characters, the resulting tweet is empty of any text whatsoever, the character countdown is 140. I could expect truncation in this case, although it does not seem to be documented in the class directory anyway, which happens when the initial text is too long , but I can agree that I need to truncate to the maximum length of the tweet before moving on to setInitialText .
I do not understand that some messages shorter than 140 characters also generate an empty tweet code.
Initially, I saw what seemed like a perfectly correct line, which did not have 139 characters. I noticed that shortening the string made it work. But after a lot of experimentation, I also noticed that replacing the URL that appeared inside the text with random text of the same length made it work. In other words, the URL itself is causing the problem.
So I thought that there might have been something strange about the URL that I used, but I brought it to that. It works:
NSString *body = @"............................................................................................................................................";
until it
NSString *body = @"............http://a........................................................................................................................";
remarks:
- They are 140 characters long (and report this to the console using
[body length] ). The only difference is that there is something vague url embedded in the middle of the second. - The position of the URL inside the string does not seem to matter, but if I change any of these non-periodic characters to a period (thus it no longer looks like a URL), it stops being broken.
- If I shorten a broken razor 14 periods from the end, it works. That is, this particular URL embedded in periods for a total length of 126 characters is perfect. 127 or more. It is unclear how, or if this refers to the length of the URL itself.
Has anyone ever seen something like this? Any idea what is going on? Am I doing something wrong, or is the iOS Twitter platform broken?
ios frameworks twitter
Paul lettieri
source share