我正在尝试将Apple Pay应用到我的应用中。我已经设置了两次商家ID,我已经通过CocoaPods安装了Stripe,Stripe-Apple Pay。每次我尝试在我的设备上运行应用程序时都会崩溃。我添加了断点来尝试了解错误发生的位置,当我到达代码时,我会看到以下内容
applePayController.delegate = self
request PKPaymentRequest 0x00000001700f3180 0x00000001700f3180
applePayController PKPaymentAuthorizationViewController! nil None
然后应用程序崩溃,我收到此错误消息
function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded>
of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
-> 0x100581474 <+44>: brk #0x1
有人可以帮我弄清楚如何解决这个问题。这是我的代码
import UIKit
import PassKit
class DetailViewController: UIViewController {
let SupportedPaymentNetworks = [PKPaymentNetworkVisa, PKPaymentNetworkMasterCard, PKPaymentNetworkAmex]
let ApplePayMerchantID = "merchant.com.Flokk.FlokkV33"
var currentObject : PFObject?
@IBOutlet var EventName: UILabel!
@IBOutlet var EventTime: UILabel!
@IBOutlet var VenueName: UILabel!
@IBOutlet var Location: UILabel!
@IBOutlet var Description: UILabel!
@IBOutlet var EventImage: PFImageView!
@IBOutlet var PayButton: UIButton!
var ticketValue:NSDecimalNumber = 0.99
@IBAction func purchase(sender: AnyObject) {
let request = PKPaymentRequest()
let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
applePayController.delegate = self
//
presentViewController(applePayController, animated: true, completion: nil)
request.merchantIdentifier = ApplePayMerchantID
request.supportedNetworks = SupportedPaymentNetworks
request.merchantCapabilities = PKMerchantCapability.Capability3DS
request.countryCode = "US"
request.currencyCode = "USD"
request.paymentSummaryItems = [
PKPaymentSummaryItem(label: "Test Ticket", amount: ticketValue),
PKPaymentSummaryItem(label: "Flokk Event", amount: ticketValue)
]
}
override func viewDidLoad() {
super.viewDidLoad()
PayButton.hidden = !PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(SupportedPaymentNetworks)
if let object = currentObject {
EventName.text = object["EventName"] as? String
Description.text = object["EventDescription"] as? String
VenueName.text = object["EventVenueName"] as? String
Location.text = object["EventLocation"] as? String
Description.adjustsFontSizeToFitWidth = true
var initialImage = UIImage(named: "DidNotLoad")
EventImage.image = initialImage
if let parseEventPhoto = object["EventImage"] as? PFFile{
EventImage.file = parseEventPhoto
EventImage.loadInBackground()
}
}
}
}
extension DetailViewController: PKPaymentAuthorizationViewControllerDelegate {
func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController!, didAuthorizePayment payment: PKPayment!, completion: ((PKPaymentAuthorizationStatus) -> Void)!) {
completion(PKPaymentAuthorizationStatus.Success)
}
func paymentAuthorizationViewControllerDidFinish(controller: PKPaymentAuthorizationViewController!) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
答案 0 :(得分:0)
尝试移动:
let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
presentViewController(applePayController, animated: true, completion: nil)
在purchase(sender: AnyObject)
函数的末尾。
换句话说,首先创建并配置您的付款请求,然后创建PKPaymentAuthorizationViewController