【问题标题】:how to call the apple wallet from ios app using swift如何使用swift从ios应用程序调用苹果钱包
【发布时间】:2018-12-06 05:37:31
【问题描述】:

每当用户单击我的 ios 应用程序中的将卡添加到钱包按钮时,我想显示苹果钱包添加卡页面。如何从 ios 应用程序调用苹果钱包。我在我的 ios 应用程序中启用了钱包功能,并为我的应用程序生成了钱包权利。如何使用 swift 使用 PKAddPaymentPassViewControler。请给出一些想法

【问题讨论】:

    标签: ios swift wallet passkit


    【解决方案1】:

    注意:这仅适用于发卡机构。如果要重定向用户以添加付款方式,请使用 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
      }
    
    }
    

    【讨论】:

    • 嗨。我有一个疑问,如果我想将用户卡的详细信息存储在苹果钱包中,我可以得到苹果的许可,还是可以在我的应用程序中添加权利。当用户从我的应用程序中单击添加卡按钮时,它是打开钱包应用程序还是自己自定义页面。谢谢
    • 如果我理解正确,您需要特殊权限才能将卡添加到 Apple Pay。请参阅此线程:forums.developer.apple.com/thread/13576 您不会自己创建页面,卡会从 Wallet 应用程序或 Apple 管理的区域添加。
    • 我的问题是当用户单击添加卡按钮然后他重定向到苹果钱包以添加卡详细信息?有可能吗?
    • 嗨。我在 self.present(addPaymentPassVC!, animated: true, completion: nil) 处遇到错误,即 Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value。 addPaymentPassVC 存储零值。
    • 如果您没有来自 Apple 的特殊权利,initWithRequestConfiguration 将返回 nil。
    猜你喜欢
    • 2018-01-24
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2019-03-12
    • 1970-01-01
    • 2013-03-11
    • 2014-03-25
    相关资源
    最近更新 更多