问题
I want to display apple wallet add cards page whenever user clicks the add cards to wallet button in my ios app. how to call the apple wallet from ios app. I enabled wallet capabilities in my ios app and also generate the wallet entitlements to my app. How to use PKAddPaymentPassViewControler using swift. please give some idea about it
回答1:
NOTE: This is for Card Issuers only. If you want to redirect a user to add a payment method, use the openPaymentSetup method. See my answer here for more details.
For Card Issuers, you need a special entitlement issued by Apple.
Your app must include this entitlement before you can use this class. For more information on requesting this entitlement, see the Card Issuers section at developer.apple.com/apple-pay/.
From this answer:
PKAddPaymentPassViewController
requires thecom.apple.developer.payment-pass-provisioning
entitlement key for your app. The bad news is that not anyone can submit apps with this entitlement as it requires special permission from Apple, which I believe is reserved for card issuers like banks and similar. If you believe that you qualify you need to contact Apple directly atapple-pay-inquiries@apple.com
You need to implement the delegate methods, and initialise it with a configuration.
import UIKit
import PassKit
class ViewController: UIViewController, PKAddPaymentPassViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if (!PKAddPaymentPassViewController.canAddPaymentPass()){
// use other payment method / alert user
}
let config = PKAddPaymentPassRequestConfiguration.init(encryptionScheme: PKEncryptionScheme.ECC_V2)
let addPaymentPassVC = PKAddPaymentPassViewController.init(requestConfiguration: config!, delegate: self)
self.present(addPaymentPassVC!, animated: true, completion: nil)
}
func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, generateRequestWithCertificateChain certificates: [Data], nonce: Data, nonceSignature: Data, completionHandler handler: @escaping (PKAddPaymentPassRequest) -> Void) {
}
func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, didFinishAdding pass: PKPaymentPass?, error: Error?) {
// pass added
}
}
来源:https://stackoverflow.com/questions/51060832/how-to-call-the-apple-wallet-from-ios-app-using-swift