eymengunay / php-passbook

iOS passbook library for PHP
http://eymengunay.github.io/php-passbook/
MIT License
263 stars 53 forks source link

Can't download pkpass from Chrome on iOS. #73

Closed ismail-wun-sg closed 9 months ago

ismail-wun-sg commented 6 years ago

I'm using the following code to return the pkpass to the user...

<?php
    $pkpass_file = 'passwebservice/output/' . $serial_number . '.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="' . $serial_number . '.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);
?>

The pass can be successfully downloaded and installed to my Apple Wallet when I access the page using Safari on iOS.

But when I try to do the same on Chrome on iOS, I get the following message:

Sorry, your Pass cannot be installed to Passbook at this time.

Anyone here encountering a similar problem? Is there anything that needs to be modified in the code to handle downloading from Chrome on iOS?

FawadNL commented 5 years ago

Yes, that is a common Apple Server restriction. They only allow if browser origin is Safari. The only thing you can do is force system browser to be used when user tries to download Apple pass by setting the target to "_system". It worked for me.

Sample PHP code:

echo '<a href="' . $displayFileName . '" target="_system"><img src="' . plugin_dir_url( __FILE__ ) . 'includes/add-to-apple-wallet.jpg" width="100px" /></a>';

dkumar1991 commented 4 years ago

I am having same issue while adding pass to the wallet on firefox and chrome.

I tried <a href="' . $displayFileName . '" target="_system"><img src="' . plugin_dir_url( __FILE__ ) . 'includes/add-to-apple-wallet.jpg" width="100px" /></a> but not worked for me.

AverageCakeSlice commented 2 years ago

Just as an update, I'm pretty sure this no longer works in some cases on iOS 14 and beyond, since you can change the default browser app, so _system will target whatever is set as the default browser, not Safari in all cases.

razvanphp commented 9 months ago

Not sure this library can do anything to fix this, so I'll close the issue for now. Please suggest some ideas and we can reopen and discuss potential workarounds, if there are any.