每当用户在我的 iOS 应用程序中单击添加卡片到钱包按钮时,我想显示苹果钱包添加卡片页面。如何从 ios 应用程序调用苹果钱包。我在我的 ios 应用程序中启用了钱包功能,还为我的应用程序生成了钱包权利。如何使用 Swift 使用 PKAddPaymentPassViewControler。请给出一些想法
最佳答案
注意:这仅适用于发卡机构。如果要重定向用户以添加付款方式,请使用 openPaymentSetup方法。 See my answer here for more details.
对于发卡机构,您需要 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/.
来自 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
您需要实现委托(delegate)方法,并使用配置对其进行初始化。
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
}
}
关于ios - 如何使用swift从ios应用程序调用苹果钱包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51060832/