How to download contact (vcard .vcf) from a webpage direct to iPhone in Mobile Safari [iOS7 UPDATE! – now supported Sept 18th 2013]

Well I never thought I would see the day but finally, iOS7 now supports import of VCARDs from web pages directly.  Check it out for yourself from http://iphone.mobicontact.info and click “Download VCARD directly” which links to http://iphone.mobicontact.info/iphonecontact.vcf.

And even better you can have it as a QR code now on your business cards… see iOS7 supports VCARD .vcf download – AT LAST!!!

The solution below should still work for older versions of iOS but it looks like they may have broken it in iOS7. Some extra user agent sniffing solves the problem and demo has been updated accordingly.

function isiOS7($user_agent=NULL) {
if(!isset($user_agent)) {
$user_agent = isset($_SERVER[‘HTTP_USER_AGENT’]) ? $_SERVER[‘HTTP_USER_AGENT’] : ”;
}
return (strpos($user_agent, ‘OS 7’) !== FALSE);
}

# Output file contents – simple version
if(!isIphone() || isiOS7()) {
# Send correct headers
header(“Content-type: text/x-vcard; charset=utf-8”);
// Alternatively: application/octet-stream
// Depending on the desired browser behaviour
// Be sure to test thoroughly cross-browser

header(“Content-Disposition: attachment; filename=\”iphonecontact.vcf\”;”);
# Output file contents
echo file_get_contents(“iphonecontact.vcf”);
exit();
}

=== ORIGINAL POST ===

So apparently it is not possible to download contact files (VCARD) direct to your iPhone (BUT IT IS NOW WITH iOS7) from a web page using Mobile Safari.  Think again – what if you attached a VCARD to a calendar appointment from the same web page?  iOS 5+ handles VCALENDAR!!! It’s not a perfect solution but pretty close so what follows is a full description of an alternative method for downloading contacts from a web page to an iPhone via Mobile Safari. The basic idea is to attach the required contact information as a file in a calendar event which IS handled by mobile safari.  The contact file itself is base64 encoded in the calendar file on the fly using a simple PHP script. Full source code Included with Mobile Safari and Mobile Chrome support from a single download PHP file.

Continue reading How to download contact (vcard .vcf) from a webpage direct to iPhone in Mobile Safari [iOS7 UPDATE! – now supported Sept 18th 2013]

iOS7 supports VCARD .vcf download – AT LAST!!!

At long last, Apple have decided to support VCARD file download from web pages in iOS7 and allow the .vcf file to be imported into your contacts application with a few key presses.

And what’s more you can even link to your contact information using a QR code – so now your information can change on the web but your business card need not.

qr-vcard

Just retested my demo web app at http://iphone.mobicontact.info to find that it appears they may have messed around with my calendar solution as the .ics file is not recognised (I will test later).  Still, downloading the vcard file directly now works.

The user agent string for an iPhone4S running iOS7 is :

Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 

ios7-import-vcard-from-web-page

While I’m here just seen that they have broken the “tel:” links used to initiate calls in Home Screen launched apps – thanks a lot, Apple. That’s several clients’ web apps that don’t work now!

Paypal donations?

What a pleasant surprise that several of you have asked if I can provide a Paypal address for you to make a donation.  Whilst I never wrote these blogs with that in mind, there has been such a significant uptake and quite a few questions and many hours of support that if you really do feel the need to buy me a beer then just use the demo app to send me a quick message and I’ll reply with a paypal link for you.

Thanks for your support and any amount small or large that you give will be gratefully received.

One last thing, if the documentation and source code gets a little out of sync or the demo apps evolve and no longer reflect the original post, please be patient and just send me a message – I’ll try to help with any problems you may have.

More iPhone vcard download hints and tips plus experiences from other users

It’s been nine months since I first wrote the original post for using a calendar appointment as a wrapper for a contact download to bypass Apple’s unfathomable determination to prevent VCARD download direct from web pages.

As you can see from all the comments and questions on the original post, it has caused quite a stir with several examples that I know of being deployed on professional sites.  So I thought would write a bot more about my experiences helping out those of you kind enough to get in touch.

  1. There are now three demos available for you to test, download and use free of charge
  2. The original demo iPhone Contact Download Demo used jQuery Mobile and I included a complete source code application for you to download. In that JQM example I was using rel=”external” to force download of the links and everything seems to work fine – after a few iterations that posters pointed out to catch things like Chrome browser on the iPhone and UiWebView anomlaies.  The download.php file contains all the user agent sniffing and detection to handle a variety of browsers and platforms. I think the presence of rel=”external” is what allows this demo to work successfully for both Android and iPhone users.  I don’t know for sure but I think it moght be that this forces some kind of page load (possibly via AJAX) without the “harshness” of the deprecated HTML target=”_blank”.
  3. BUT we hit a problem when you removed the jQuery Mobile and tried the same demo but plain ol’ HTML as can be seen here HTML contact download to iPhone.  You’ll have to take my word for it that what would appear to be a very simple exercise soon became very frustrating as I tried various Android browsers and came unstuck downloading the simple VCARD (via a direct link to the .vcf file) to a Samsung Galaxy S2 native browser.  It insisted on treating it as text even when I served the correct headers in PHP and added AddType text/x-vcard to .htaccess.  The only way I could get it work was with a modified .htaccess as shown below.  Now I know this should be identical to what I was doing in PHP but I just couldn’t get it to work – see the many examples at Developer Code
    <FilesMatch "\.vcf$"> 
    ForceType text/x-vcard;charset=utf-8 
    Header set Content-Transfer-Encoding binary
    Header set Content-Disposition "attachment; filename='contact.vcf';"
    Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, private"
    </FilesMatch>
  4. The above was highlighted when we tried to pull the solution away from JQM and into a Joomla component as requested by one blogger. The Joomla solution used PHP and HTML but would not work reliably until we removed the target=”_blank” from the anchor tag for an iPhone download link and added it for the direct VCF file download for all other phones BUT we also needed the .htaccess to server the correct content type text/x-vcard. Supposedly this content type has been deprecated in favour of text/vcard but in my experience someone for got to tell the browser developers on Android phones and I had limited success with the later (standardised?) version.
  5. As the JQM demo was a fully functioning web app using the HTML5 offline cache you need to be familiar with clearing your “normal” cache AND the HTML5 cache as detailed by the manifest.php – I use chrome so you can view what is saved by going to chrome://appcache-internals/.  If you’ve got it setup correctly, then the offline cache should be refreshed automatically on detecting a change in the index.php file but if you ever want to be sure – delete both your cache contents.
  6. You’ll find a User Agent Switcher such as Ultimate User Agent invaluable for simulating and debugging the various mobile browser behaviours.  Simply set your Chrome browser (or other with equivalent user agent switching plugin) to iPhone and watch it download the vCAlendar .ics file rather than the vCard .vcf file.
  7. And of course, for the really tricky problems you’ll need a PHP debugger – I use Netbeans but I am sure there are many others to choose from.

How to update Windows 8 Evaluation Pre-Release Build 8400 to Windows 8 Pro

Simple answer is you can’t!  (I say this so that someone will take on the challenge and solve the problem)

Can you believe that it is not possible to just buy the Windows 8 Pro upgrade which will automatically upgrade Windows XP/Vista/7 using the Upgrade Assistant and install it when running the evaluation release of Windows 8?

What on earth were Microsoft thinking when they forgot about the thousands of us who upgraded their perfectly working Windows 7 machines to get a glimpse of Windows 8, expecting to be able to simply buy the official Windows 8/8 Pro license when it was released.

Continue reading How to update Windows 8 Evaluation Pre-Release Build 8400 to Windows 8 Pro