ios - Inaccurate character counts with SLComposeViewController (twitter) and TWTweetComposeViewController -
i'm presenting ios twitter share sheets (slcomposeviewcontroller
on ios 6, twtweetcomposeviewcontroller
on ios 5) in app user-selected text , link. if text long, 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 this, character count gets messed up. setinitialtext
returns yes
before i'm down expected length, , share sheet comes showing overflow text. example, if link 35 characters long, share sheet accepts string of length 117 after decrementing couple of times. 117 + 35 = 152 (12 over), share sheet shows 9 over.
am using api wrong, or there bug in character counts? this article on twitter's dev site seems suggest there's issue, it's on year old.
edit: result same if append link end of text manually instead of using addurl
method.
the length
method of nsstring
has limitations composed character sequences affecting results.
the number returned includes individual characters of composed character sequences, cannot use method determine if string visible when printed or how long appear.
Comments
Post a Comment