Q:

When using SLServiceTypeTwitter, what's the longest a link can be, and how do I format the tweet to make sure it's not longer?

Right now when the user selects an article to share via Twitter, I want to give the link as well as the title of the URL, but I'm having difficulty with figuring out how long link counts for with Twitter.
Are links shared with Twitter via the iOS API counted as the full length of the URL, or where it's a URL, given a special rule/length? If so, how do I calculate the length. I've read a few articles saying links are considered 22 characters long, but that recently changed from 20. What if it changes again?
So how long is a link? And once I figure it out should I just use 140 - link length to figure out how many characters to use for the title?

A:

Per the twitter docs, all URL's are shortened using their t.co service - including those submitted via SLComposeViewController.  The docs say that if you attempt to add a long URL to a SLComposeViewController it will succeed or fail based on available space, and that it is the shortened URL that is used when making this decision.
They don't give you a character count but they do tell you if what you're trying to add will fit.
Excerpt from the linked Twitter docs, emphasis mine:

Below is an example of the above steps. Note that the methods for
  setting initial content respond with Boolean values; this allows you,
  the developer, to not have to worry about the current count of
  characters in the body of the Tweet that you are initializing. If the
  method returns YES, there was enough room to add the content. If the
  method returns NO, the content you attempted to add would result in a
  Tweet longer than 140 characters. The logic for character counting
  also takes into effect the current number of characters required for
  t.co URL wrapping.

I haven't tried but you could likely determine the number of characters available after first adding your URL by iteratively calling setInitialText: with a string with decreasing character count, starting with 140 characters.

