<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Code Train &#187; mobilesafari</title>
	<atom:link href="http://thecodetrain.co.uk/tag/mobilesafari/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecodetrain.co.uk</link>
	<description>Where Neil Crosby talks about coding on the train...</description>
	<lastBuildDate>Sun, 03 Apr 2011 18:15:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Adding a vCard to your iPhone Address Book from a web page</title>
		<link>http://thecodetrain.co.uk/2009/11/adding-a-vcard-to-your-iphone-address-book-from-a-web-page/</link>
		<comments>http://thecodetrain.co.uk/2009/11/adding-a-vcard-to-your-iphone-address-book-from-a-web-page/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 00:43:52 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[addressbook]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobilesafari]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scratching an itch]]></category>
		<category><![CDATA[vcard]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=334</guid>
		<description><![CDATA[<p>It can&#8217;t be done. Well, not obviously anyway.</p>

<p>A couple of weeks ago, I realised that <a href="http://neilcrosby.com/vcard">my public vCard</a> was less useful than it might be.  One of the specific reasons that I created it was to make it easy for people to add a bunch of my contact information to their address books when I met them, rather than them having to manually type in a whole load of stuff that was on a business card.  It turns out that this is great when that person&#8217;s sat at their own computer, but if they&#8217;re (for example) using an iPhone then things become a little more difficult.</p>

<p>You see, the iPhone doesn&#8217;t like to use MobileSafari to download files.  That&#8217;s fine in general &#8211; you don&#8217;t get a filesystem to peruse on the iPhone, so the only way that downloads would be useful is if the iPhone already knows what to do with them.  That&#8217;s why applications are allowed to register their own custom URL schemes. </p>

<p>Unfortunately, by default the iPhone only registers <a href="http://developer.apple.com/safari/library/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html">a few URL schemes</a> for use within web pages &#8211; <code>mailto:</code>, <code>tel:</code> and <code>sms:</code> as pseudo protocols, as well as specific URL structures for Google Maps, YouTube and iTunes links.  This makes it impossible to do things like adding an address to the Address Book or an event to the Calendar with a single click on a link in a webpage &#8211; you just get a message that reads &#8220;Download failed. Safari cannot download this file&#8221;.</p>

<p>This is clearly a pain. As a phone, it seems reasonable that you should be able to easily add contacts to your Address Book. Unfortunately, either Apple thinks you shouldn&#8217;t be able to do this from a webpage or they just didn&#8217;t consider it as a usecase.</p>

<p>It turns out that they did consider that you might like to open email attachments though. If someone sends you an email that contains a VCF file then you <em>are</em> able to open it and see its contents. If you then scroll down to the bottom of the file you&#8217;re greeted with two options, allowing you to &#8220;Create New Contact&#8221; or &#8220;Add to Existing Contact&#8221;.  Suddenly a world full of contact adding goodness is opened up to you.</p>

<p>So, what I&#8217;ve decided to do with my vCard is a little bit of user agent sniffing in my PHP. Currently I assume that every other device in the world other than the iPhone will do something sensible with the normal VCF file (or the microformatted data that&#8217;s on the page itself), so I listen out for the iPhone&#8217;s user agent. If I see it then I swap out the link to download the VCF file with one that takes the user to a page containing a form allowing them to enter their email address. Once they do, the VCF file is immediately emailed to them and they can add my card to their address book.</p>

<p>Right now the look and feel of the <a href="http://neilcrosby.com/vcard/via-email/">the email form</a> that iPhone users are directed to could be described as rudimentary at best, but it works.  At some point in the future I&#8217;ll get round to making it look a bit more pretty.</p>

<p>As a solution, I&#8217;m fairly happy with this.  Whilst it&#8217;s nowhere near as nice as being able to simply click on a link and add a contact to your address book, it does at least mean that it becomes possible to add a contact from a web page.  Certainly it&#8217;s a better solution than not allowing users access to the content at all.  It&#8217;s also entirely possible that this solution would work for other filetypes, such as calendar events.</p>

<p>My only concern is that this problem may be in existence in other devices other than the iPhone as well.  It would almost certainly make sense to make the email option available to users of other devices as well.</p>

<p>So there you have it &#8211; to allow a user to add a contact to their Address Book from a webpage on the iPhone don&#8217;t try and get them to download it, let them receive it via email instead. </p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>It can&#8217;t be done. Well, not obviously anyway.</p>

<p>A couple of weeks ago, I realised that <a href="http://neilcrosby.com/vcard">my public vCard</a> was less useful than it might be.  One of the specific reasons that I created it was to make it easy for people to add a bunch of my contact information to their address books when I met them, rather than them having to manually type in a whole load of stuff that was on a business card.  It turns out that this is great when that person&#8217;s sat at their own computer, but if they&#8217;re (for example) using an iPhone then things become a little more difficult.</p>

<p>You see, the iPhone doesn&#8217;t like to use MobileSafari to download files.  That&#8217;s fine in general &#8211; you don&#8217;t get a filesystem to peruse on the iPhone, so the only way that downloads would be useful is if the iPhone already knows what to do with them.  That&#8217;s why applications are allowed to register their own custom URL schemes. </p>

<p>Unfortunately, by default the iPhone only registers <a href="http://developer.apple.com/safari/library/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html">a few URL schemes</a> for use within web pages &#8211; <code>mailto:</code>, <code>tel:</code> and <code>sms:</code> as pseudo protocols, as well as specific URL structures for Google Maps, YouTube and iTunes links.  This makes it impossible to do things like adding an address to the Address Book or an event to the Calendar with a single click on a link in a webpage &#8211; you just get a message that reads &#8220;Download failed. Safari cannot download this file&#8221;.</p>

<p>This is clearly a pain. As a phone, it seems reasonable that you should be able to easily add contacts to your Address Book. Unfortunately, either Apple thinks you shouldn&#8217;t be able to do this from a webpage or they just didn&#8217;t consider it as a usecase.</p>

<p>It turns out that they did consider that you might like to open email attachments though. If someone sends you an email that contains a VCF file then you <em>are</em> able to open it and see its contents. If you then scroll down to the bottom of the file you&#8217;re greeted with two options, allowing you to &#8220;Create New Contact&#8221; or &#8220;Add to Existing Contact&#8221;.  Suddenly a world full of contact adding goodness is opened up to you.</p>

<p>So, what I&#8217;ve decided to do with my vCard is a little bit of user agent sniffing in my PHP. Currently I assume that every other device in the world other than the iPhone will do something sensible with the normal VCF file (or the microformatted data that&#8217;s on the page itself), so I listen out for the iPhone&#8217;s user agent. If I see it then I swap out the link to download the VCF file with one that takes the user to a page containing a form allowing them to enter their email address. Once they do, the VCF file is immediately emailed to them and they can add my card to their address book.</p>

<p>Right now the look and feel of the <a href="http://neilcrosby.com/vcard/via-email/">the email form</a> that iPhone users are directed to could be described as rudimentary at best, but it works.  At some point in the future I&#8217;ll get round to making it look a bit more pretty.</p>

<p>As a solution, I&#8217;m fairly happy with this.  Whilst it&#8217;s nowhere near as nice as being able to simply click on a link and add a contact to your address book, it does at least mean that it becomes possible to add a contact from a web page.  Certainly it&#8217;s a better solution than not allowing users access to the content at all.  It&#8217;s also entirely possible that this solution would work for other filetypes, such as calendar events.</p>

<p>My only concern is that this problem may be in existence in other devices other than the iPhone as well.  It would almost certainly make sense to make the email option available to users of other devices as well.</p>

<p>So there you have it &#8211; to allow a user to add a contact to their Address Book from a webpage on the iPhone don&#8217;t try and get them to download it, let them receive it via email instead. </p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2009/11/adding-a-vcard-to-your-iphone-address-book-from-a-web-page/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

