How to set MIME type of application/vnd.apple.pkpass in order to share pass by link or email

隐身守侯 提交于 2020-01-09 05:06:36

问题


I just created an app and a pass, so I can add the pass to the PassBook in iPod, but I cannot share the pass by email or link from web server. From the documentation I read from Apple, I need to add a MIME type as application/vnd.apple.pkpass. However, I don't understand clearly what steps should I do. I don't know how to use MIME type.

How should I add this MIME type in order to use pass from my web service?


回答1:


Apache

Add the following line to either:

  • the .htaccess in the directory serving your .pkpass, or
  • to the mime.types file, or
  • to your appache httpd.conf or virtuatl server .conf file

Then restart Apache (not required if adding to .htaccess)

AddType application/vnd.apple.pkpass    pkpass

nginx

Add the following line to your mime.types file and restart nginx

application/vnd.apple.pkpass    pkpass;

IIS

  1. Open IIS Manager and navigate to the level you want to manage.
  2. In Features View, double-click MIME Types.
  3. In the Actions pane, click Add.
  4. In the Add MIME Type .pkpass
  5. Type application.vnd.pkpass n the MIME text box
  6. Click OK
  7. Restart IIS

If you are serving your file via a script and are not able to edit your web server config you could add the following line before any content is sent:

PHP

header('Content-Type: application/vnd.apple.pkpass');

C#

WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/vnd.apple.pkpass");



回答2:


For a pure PHP solution, add your .pkpass bundle to the server, then create the following file and name this file pass.php.

<?php   
$pkpass_file = '/path/to/your/.pkpass/file/GenericMemberCard.pkpass';

header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.apple.pkpass");
header('Content-Disposition: attachment; filename="pass.pkpass"');
clearstatcache();
$filesize = filesize($pkpass_file);
if ($filesize)
    header("Content-Length: ". $filesize);
header('Content-Transfer-Encoding: binary');
if (filemtime($pkpass_file)) {
    date_default_timezone_set("UTC");
    header('Last-Modified: ' . date("D, d M Y H:i:s", filemtime($pkpass_file)) . ' GMT');
}
flush();
readfile($pkpass_file);

Then create a second file linking to the file you created above.

<a href="pass.php">Click to download your pass</a>


来源:https://stackoverflow.com/questions/15383552/how-to-set-mime-type-of-application-vnd-apple-pkpass-in-order-to-share-pass-by-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!