Ever wonder why the character count in the Twitter box jumps (or stays put) when you begin typing a URL in iOS share box? Wonder what the heck I’m talking about? Great question, take a moment and open a web page Safari on your iPhone (borrow a friend’s if you don’t have one) and go to Apple.com. Tapping on the Share icon located at the bottom of the screen will activate the Share and Action Sheet (best name I could find after a brief search across the web).
Notice that you have a collection of Share and Action options. In this article, we will be focusing on Twitter. Tap on it to activate the Share. NOTE: this assumes that you have a Twitter account and that account has been configured in the built-in Twitter feature of iOS framework, and no, sadly, having the Twitter app installed does not count.
Before we move forward, let’s quickly recheck our understanding of the crazy social world known as Twitter. Twitter is built on a simple concept of short, sweet, messages, 140 characters long to be exact. That’s right, every thought, every dream, every fact, needs to fit in measly 140 characters or less (some studies even recommends to grab a persons attention, it should be under 100 characters!) to successfully post into Twitter. So now that we activate our Twitter share dialog, let’s take a look at it. There are several 3 key components:
- The message
- The optional image predefined by the programmer
- Character Count
Let’s take a look at what we see on Apple.com
Now as we take a closer look, we have a message Apple, an optional image and a character count that says… wait… 140 characters – Apple (5 characters) = 135 characters, but currently the dialog says I only have 112 characters left… what gives??
That is our lead into the point of this article. I will discuss 2 topics
- How to embed the URL (Developer point of view)
- Twitter’s link standardization
How to embed the URL (and optional image) in Share
As you noticed in the above example, we have some oddly missing characters in our 140 character count control. This is because, for both convenience for the user but assurance for the marketing/business team of a given site or app, the URL is “hardcoded” behind the scenes of the share so it is not lost. How is this done? You can follow the guide described here – iOS Developer Library – SLComposeViewController Class Reference
If you execute the function addURL it will be embedded. If on the other hand, you prefer to display the URL to the user in the Twitter composer, you can add the URL within the SetInitialText function. Worried about composing a URL dynamically while still adhering to the 140 character limit? Don’t worry, Twitter’s got your back!
Twitter’s Link Standardization
Let’s go back to our original example, sharing Apple.com with Twitter. When we left off, the Initial Text in the share was Apple with the character countdown at 112 characters. Now append “ http://” to the end of the existing content and notice the count is now
Notice the character count dropped to 104, makes since (112 – 8 new characters, including the space = 104). Ready for your mind to go crazy? Add an a after that, I dare ya!
We are now down to 89 characters! Never thought a was so powerful, eh? OK, a really is not that powerful. What is going on, is that the iOS dialog is aware of special URL management Twitter invokes. You see Twitter, converts any URL automatically to a internal standardized URL of just 22 characters. This is an amazing feature for us mobile developers as it gives us a standard to code on. Worried about those dynamic links eating up all the characters? No worries, just keep the 22 characters in mind, and use the addURL function and you can share with confidence.
Want to learn more about this 22 character limit? Checkout this link – Posting links in a Tweet