iPhone:如何让safari识别出vcard?

ut_est 发布于 2019-11-10 iphone 最后更新 2019-11-10 12:11 42 浏览

我正在尝试创建QR码,以便iPhone用户可以导入我的地址簿信息。我正在做这件事:

  • 在我的网络服务器上放置一个VCF(vcard)文件
  • 创建包含此网址的QR图像。
http://markharrison.net/mh-vcf-small.png 这是在我的桌面浏览器(它打开与通讯录应用程序的vcard)。 在iPhone上,QR阅读器成功告诉safari访问vcard,但safari抱怨说它不知道如何处理vcard。我已确认Content-Type: text/x-vcard正在发送。 所以,我的问题是:
  • 如何让Safari识别我的vcard?
  • Safari浏览器是否支持另一种卡片格式?
已邀请:

hquas

赞同来自:

我刚刚在我的博客上发布了一个替代解决方案,该解决方案描述了如何将联系人文件作为附件添加到日历文件中,该日历文件由iOS5以后的移动safari处理。 http://mobicontact.info/iphone/download-contact-from-web-page/ 该博客显示了完整的解决方案,包括整个过程的源代码和图像,因此比我在Stack Overflow上可以提供的内容更容易阅读。需要注意的要点是Apple使用:

ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;
X-APPLE-FILENAME=iPhone Contact.vcf:
QkVHSU46VkNBUkQNClZFUlNJT046M…etc… [base64 encoded VCARD]
用于VCALENDAR文件中的嵌入式VCARD。创建一个VCALENDAR文件,然后在其中对您的VCARD进行base64编码 - 下面的代码片段(我博客上的完整详细信息)
<?php
# Send correct headers      
header("Content-type: text/x-vcalendar; 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.ics\";");
# Output file contents - simple version
#echo file_get_contents("iphonecontact.ics");
# Generate file contents - advanced version
# BEGIN:VCALENDAR
# VERSION:2.0
# BEGIN:VEVENT
# DTSTART;TZID=Europe/London:20120617T090000
# DTEND;TZID=Europe/London:20120617T100000
# SUMMARY:iPhone Contact
# DTSTAMP:20120617T080516Z
# ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;
#  X-APPLE-FILENAME=iphonecontact.vcf:
#  QkVHSU46VkNBUkQNClZFUlNJT046My4wDQpOOkNvbnRhY3Q7aVBob25lOzs7DQpGTjppUGhvbm
#  UgQ29udGFjdA0KRU1BSUw7VFlQRT1JTlRFUk5FVDtUWVBFPVdPUks6aXBob25lQHRoZXNpbGlj
#  b25nbG9iZS5jb20NClRFTDtUWVBFPUNFTEw7VFlQRT1WT0lDRTtUWVBFPXByZWY6KzQ0MTIzND
#  U2Nzg5MA0KRU5EOlZDQVJE
# END:VEVENT
# END:VCALENDAR
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "BEGIN:VEVENT\n";
echo "SUMMARY:Click attached contact below to save to your contacts\n";
$dtstart = date("Ymd")."T".date("Hi")."00";
echo "DTSTART;TZID=Europe/London:".$dtstart."\n";
$dtend = date("Ymd")."T".date("Hi")."01";
echo "DTEND;TZID=Europe/London:".$dtend."\n";
echo "DTSTAMP:".$dtstart."Z\n";
echo "ATTACH;VALUE=BINARY;ENCODING=BASE64;FMTTYPE=text/directory;\n";
echo " X-APPLE-FILENAME=iphonecontact.vcf:\n";
$vcard = file_get_contents("iphonecontact.vcf");        # read the file into memory
$b64vcard = base64_encode($vcard);                      # base64 encode it so that it can be used as an attachemnt to the "dummy" calendar appointment
$b64mline = chunk_split($b64vcard,74,"\n");             # chunk the single long line of b64 text in accordance with RFC2045 (and the exact line length determined from the original .ics file exported from Apple calendar
$b64final = preg_replace('/(.+)/', ' $1', $b64mline);   # need to indent all the lines by 1 space for the iphone (yes really?!!)
echo $b64final;                                         # output the correctly formatted encoded text
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
?>

wnihil

赞同来自:

内容太长未翻译