【发布时间】:2018-12-06 05:37:31
【问题描述】:
每当用户单击我的 ios 应用程序中的将卡添加到钱包按钮时,我想显示苹果钱包添加卡页面。如何从 ios 应用程序调用苹果钱包。我在我的 ios 应用程序中启用了钱包功能,并为我的应用程序生成了钱包权利。如何使用 swift 使用 PKAddPaymentPassViewControler。请给出一些想法
【问题讨论】:
每当用户单击我的 ios 应用程序中的将卡添加到钱包按钮时,我想显示苹果钱包添加卡页面。如何从 ios 应用程序调用苹果钱包。我在我的 ios 应用程序中启用了钱包功能,并为我的应用程序生成了钱包权利。如何使用 swift 使用 PKAddPaymentPassViewControler。请给出一些想法
【问题讨论】:
注意:这仅适用于发卡机构。如果要重定向用户以添加付款方式,请使用 openPaymentSetup 方法。 See my answer here for more details.
对于发卡机构,您需要 Apple 颁发的特殊权利。
您的应用必须包含此权利才能使用此类。 有关申请此权利的更多信息,请参阅卡 developer.apple.com/apple-pay/ 上的发行人部分。
来自this answer:
PKAddPaymentPassViewController需要com.apple.developer.payment-pass-provisioning权利 您的应用程序的密钥。坏消息是没有人可以提交应用程序 此权利,因为它需要 Apple 的特别许可,我 相信是为银行等发卡机构保留的。如果你 相信您符合条件,您需要直接联系 Apple:apple-pay-inquiries@apple.com
您需要实现委托方法,并使用配置对其进行初始化。
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
}
}
【讨论】:
initWithRequestConfiguration 将返回 nil。