Hyperlinks don’t necessarily point to other websites, but they can also link to applications installed on your computer or mobile device (if you’ve spent some time writing HTML markup, I’m sure you have seen mailto: links).
The SMS URI scheme essentially does the same thing, but instead of opening an email client, it opens the device’s native messaging app (like iMessages). The URI scheme is specified in RFC 5724.
What I wanted to do:
- Open a native messaging application
- Pre-populate the message field with an ingredient list (for cooking)
- Let the user use his or her address book to select a recipient and send the ingredient list
Sounds simple, right? Not if you’re using an Apple device. First of all, the SMS links documentation for iOS states that “The URL string must not include any message text or other information. […] ” (SMS Links documentation for iOS)
This is wrong. Having read this post about SMS links, I was quite sure that it would work. The code sample
works on iOS 6 + 7 devices (the colon is normally followed by the phone number, which can be omitted). Turns out it doesn’t work on iOS 8. On iOS 8, you have to use
For Android devices, you have to use
Accordingly, a full link for an iOS 8 device would look something like
<a href="sms:&body=My%20text%20for%20iOS%208">Send SMS</a>
Here’s a gist that wraps it all up:
This means that you need to maintain client or server side code for operating system and version (!) detection to build SMS links that work universally. Well done. The RFC was last updated half a decade ago. Still, Apple hasn’t managed to implement the URI scheme properly.
Note: An obvious shortcoming of RFC 5724 is that it does not document how to use the SMS URIs without specifying a phone number very well, which may be the root of the problem…