The Code Train

Where Neil Crosby talks about coding on the train…

RSS Entries

Adding a vCard to your iPhone Address Book from a web page

Posted on November 29th, 2009 by Neil Crosby. Filed under Blog Posts.

It can’t be done. Well, not obviously anyway.

A couple of weeks ago, I realised that my public vCard 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’s sat at their own computer, but if they’re (for example) using an iPhone then things become a little more difficult.

You see, the iPhone doesn’t like to use MobileSafari to download files. That’s fine in general – you don’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’s why applications are allowed to register their own custom URL schemes.

Unfortunately, by default the iPhone only registers a few URL schemes for use within web pages – mailto:, tel: and sms: 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 – you just get a message that reads “Download failed. Safari cannot download this file”.

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’t be able to do this from a webpage or they just didn’t consider it as a usecase.

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 are able to open it and see its contents. If you then scroll down to the bottom of the file you’re greeted with two options, allowing you to “Create New Contact” or “Add to Existing Contact”. Suddenly a world full of contact adding goodness is opened up to you.

So, what I’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’s on the page itself), so I listen out for the iPhone’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.

Right now the look and feel of the the email form that iPhone users are directed to could be described as rudimentary at best, but it works. At some point in the future I’ll get round to making it look a bit more pretty.

As a solution, I’m fairly happy with this. Whilst it’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’s a better solution than not allowing users access to the content at all. It’s also entirely possible that this solution would work for other filetypes, such as calendar events.

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.

So there you have it – to allow a user to add a contact to their Address Book from a webpage on the iPhone don’t try and get them to download it, let them receive it via email instead.

Tags: , , , , , , ,

If you enjoyed this post, subscribe to The Code Train and read more when I write more.

30 Responses to “Adding a vCard to your iPhone Address Book from a web page”

  1. Damn! I’ve been struggling with this myself. It’s the sort of pig-headed obstinance that gets Apple a bad name. A simple enough thing to do, and so far every other mobile phone I’ve tested handles it correctly. Your solution is fine in some circumstances, but still an inexcusable break in the user experience. Bad Apple!

  2. I’ve been trying to solve this problem for a while – with no solution. A couple of companies use the solution you highlight in your blog, but surely.. there must be a way to do this?!

    If you find anything, I would love to hear from you!

    Nick

  3. The blackberry has the same issue. Lets hope they fix this soon

  4. Thanks for the info, Neil! Was just beating my head about this and now you’ve offered a workable solution. :) Hopefully the companies making phone software will realise that people do actually get files from a browser in such a way and support it better.

    Andy

  5. Wow! Life saver! Thanks :)

  6. Hi Neil,

    thanks for the hint. But on my iPhone (OS 3.1.2) it does not work. It says “Safari cannot load this file”.

    Oh well, I see. It works with the “standard”-mail-app. But not when I read the web-mail via Safari.

    Oh man, didn’t thought this causes so much trouble. Thanks, Neil, for providing this solution. Stefan

  7. Would you be able to share the code?

  8. @Ben – sorry about that, sharing the code would absolutely be the Right Thing™ to do, wouldn’t it? I’m not quite sure how I forgot to do it the first time around to be honest, since it’s up on GitHub!

    So, in all its glory here’s a link to the proof of concept iPhone vCard downloadification code.

  9. I found an even better way to add vcard information from a website. I just blogged about this on my site and it involves using the new Microsoft color barcode tags to create vcards on their site and then exporting an image for use on printed business cards or wherever.

    I posted an image on my site that contains just a URL, but it works when taking a picture of the image using the iPhone app: TagReader. Other mobile devices are supported too.

    This way, bloggers can post an image of their tag online and people who want to save the information to their phone can do so by taking a picture of the screen.

    Check out my full blog post here: http://www.ledfrog.com/2010/04/using-digital-barcodes-on-your-business-cards/

  10. I found a way to do it with just a few required clicks useing Google maps! If you would like to know how, read on my HowTo-side..

  11. Seems like you’ll need to update your post Neil. :)

    Try Qrafter for iPhone. You’ll see that you can download a complete vCard using it. To learn more, see: http://keremerkan.net/posts/how-to-download-a-vcard-on-iphone-using-qrafter/

  12. This is the solution we implemented at contactmonkey.com. We make it easy for the people you email to grab your contact info – regardless of what address book they use. Thanks for the tutorial!

  13. Thanks Neil, after doing a lot of research I implemented the solution, that you’ve described here! Although there are a few other solutions out there by now they all have their downsides and yours is the best workaround I could find.

  14. Such a simple solution and it had escaped me! Thanks for the form idea! Apple continues to be a live hate relationship for me, the iPhone is awesome, but little cr*p like this is very frustrating… Wish they would get their act together with Adobe and integrate FLASH!, how freaking’ stupid is that!? I also wanted o suggest that you can do a simple link on youelr webpage using the “Mail to:________?attachment”, and link to the vCard so end up as an attachment to the email and the end user can mail the vCard to themselves… A little crude, but works. ONWARD!

  15. what do i have to put where???? yeah I’m a newbie.

  16. Did iOS 5 fix this?

  17. Just tried downloading this vCard file (http://www.jackfruitdesign.com/old/downloadvcard/) on my iPhone 4S…and it doesn’t let me add it to my addresses.

    So, I guess iOS 5 still doesn’t handle vCards correctly.

  18. If you happen to have Tap Forms installed on your iPhone then iOS 5 allows you to download the VCF file and send it to Tap Forms, and then Tap Forms can create a new Contacts entry. It’s a bit tortuous but it works.

  19. Have you considered turning your contact information into a QR code?

    Most cell phones here in Japan are capable of transferring contact information via an IR port. The iPhone, however, lacks this capability. I’ve gotten around it by turning my contact information into a QR code, which other people can scan and then save as contact information.

  20. The problem with creating a QR code for your downloadable contact information is that a high percentage of users are NOT trying to get your contact info directly from your printed business card they are trying to get it while already on your mobile site. So unless they happen to carry around 2 iphones (one to pull up the QR code and one to snap it) it is useless for this use case. Its actually not even a problem with iOS its a problem with the safari browser. Even the android browser had difficulties with this that haven’t been corrected at the browser level. At least with android a simple .htaccess correction fixed the problem and allowed you to download .vcf files to the contacts. With safari though this is still a problem and the php solution to email the .vcf file is the only working solution that i have heard of or seen. Using google maps to get what you want is a clever solution but lets face it if iphone users were clever it really wouldn’t be that hard for them to get your contact info into their phones so as developers we keep drudging through work arounds to get people that think their phone is amazing to keep believing it! Good luck i look forward to this being the next standards issue for cross platform development, lol.

  21. Thanks very much, Neil. This is really helpful!! Also thank you Jan-Hendrick. I didn’t think of that at all. Kerem Erkan, Thank you, also. I love that Qrafter finally does this correctly (allegedly – I havent tried it yet)… but lose the smugness (and it’s customary here to disclose when you are pushing your own app). We are the vcard publishers. Not the people with scanners. It doesn’t matter what scanner we have. It matters what scanner the people we meet have. And when I get really lucky and stumble into someone that knows what QR is, sadly they typically don’t have your scanner.

  22. Hmm, sorry if my comment looked like it was written in full smugness, I was trying to be more friendly. Anyhow, point taken!

  23. I dont have an iphone, I have an android. Which makes testing exciting! In light of all the posts, and the time since this was coded, is this still a needed piece of code? Or are all you apple users now able to import vcf files? Either way, thank you Neil for your work, and for sharing it so generously. Its very much appreciated, and thank you to all the above who added. I truly appreciate all the time you have all given so willingly and freely.

  24. Well it doesn’t work… it works only when i arrived an email. Then i can import the attached vcf card…

    I have found an site. you must register and put you name … in the site… u get an qrcode with the link to ure own vcard site and there it is possible to send the vcf from the site to you… i find it great! b-card.us is the url…

    greets

  25. I have just published an alternative solution on my blog which describes how to attach the contact file as an attachment to a calendar file which is handled by mobile safari. Please have a look…

    http://mobicontact.info/iphone/download-contact-from-web-page/

  26. iOS6 doesn’t contains Google Maps anymore, so you get redirected to the Google website, which s*cks

  27. Check out my fix for the same issue, will be sharing the secret sauce soon. I didn’t like the idea of making the users type in their email address on mobile, because no matter how good soft-keyboard “x” is, it’s still better to not have to type at all. You can view my solution at acedrew.com/vcard

    Andrew Rodgers

  28. “Adding a vCard to your iPhone Address Book from a web page

  29. You think they would have fixed this in iOS6. So stupid.

  30. I’m not that much of a online reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your site to come back down the road. All the best

Comments RSS

Leave a Reply

TheCodeTrain Theme by Neil Crosby, Powered by WordPress