如何使用 swift 从 ios 应用调用苹果钱包

how to call the apple wallet from ios app using swift

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

注意:这仅适用于发卡机构。如果要重定向用户以添加付款方式,请使用 openPaymentSetup method.

对于发卡机构,您需要 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/.

来自

PKAddPaymentPassViewController requires the com.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 at 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
  }

}