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

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

本文介绍了如何使用swift从ios应用程序调用苹果钱包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户单击我的ios应用程序中的向钱包添加卡"按钮时显示苹果钱包添加卡"页面.如何从ios应用程序调用苹果钱包.我在ios应用程序中启用了钱包功能,还生成了我的应用程序的钱包授权.如何使用swift使用PKAddPaymentPassViewControler.请给一些想法

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

推荐答案

注意:这仅适用于发卡机构.如果您要重定向用户以添加付款方式,请使用 openPaymentSetup 方法. 有关更多详细信息,请参见此处的答案.

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.

对于发卡行,您需要由Apple发行的特殊权利.

For Card Issuers, you need a special entitlement issued by Apple.

来自此答案:

您需要实现委托方法,并使用配置对其进行初始化.

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
  }

}

这篇关于如何使用swift从ios应用程序调用苹果钱包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:17