Create an ‘iMessage Me’ link

With the launch of iMessage on the Mac earlier this month, we now have what I think to be the perfect IM solution – cross device (not platform, sadly) syncing of message histories – why couldn’t anyone do this earlier?

You may like to add an iMessage Me link to your website/blog to make it easier for people visiting your page from a Mac or iOS device (iPhone, iPad, iPod touch) – just a tap and they’re all set to iMessage you.

For whatever reason, iOS and OS X use different URL schemes for iMessage – I understand why Messages for Mac may not want to adopt the sms: scheme, but I find it odd that iOS doesn’t like the imessage: scheme. So we’re left with two different schemes depending on the platform your visitor is using.

Using some fancy PHP trickery, here’s some code that will detect your visitor’s operating system, and based on that display either a sms: link or an imessage: one.

$useragent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/Macintosh/',$useragent)) $os = 'imessage';
elseif(preg_match('/iPhone/',$useragent)) $os = 'sms';
else $os = 'sms';
echo $os;

Throw this inbetween your standard link and you’re good to go.

For example:

<a href="">iMessage me!</a>

Or, put together:

<a href="<?php $useragent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/Macintosh/',$useragent)) $os = 'imessage'; elseif(preg_match('/iPhone/',$useragent)) $os = 'sms'; else $os = 'sms'; echo $os; ?>">iMessage me!</a>
  1. have you thought about making a full html code for this, php for some reason won’t work with a dropbox public site. could you possibly write a code for me that does
    <a href="”>

    1. Hey Vic;
      Unfortunately PHP is used here to detect whether the user is on a Mac or iOS device, and then change the URL to suit.

      You can use a or a but remember that the SMS link only works on iOS, and the iMessage link only works on the Mac; it’ll throw up an error on iOS.

  2. Is it possible that it activate a message and send to us?

    E.g. When a user directly click on the link, it will send us notification automatic on clicking and we can start the conversation. Probably with a custom message. Possible?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.