how to call the apple wallet from ios app using swift

淺唱寂寞╮ 提交于 2019-12-10 12:06:19

问题


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


回答1:


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.

For Card Issuers, you need a special entitlement issued by 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/.

From this answer:

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

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
  }

}


来源:https://stackoverflow.com/questions/51060832/how-to-call-the-apple-wallet-from-ios-app-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!