Tag Archives: ics

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]