lundi 29 juin 2015

Swift Apple Pay Crashes; PKPaymentAuthorizationViewController = nil

I am trying to implement Apple Pay into my app. I've setup my merchant ID twice and I've installed Stripe, Stripe-Apple Pay via CocoaPods. Every time I try to run the app on my device it crashes. I've added breakpoints to try and understand where the error is occurring and I see the following when I get to the code applePayController.delegate = self

request PKPaymentRequest 0x00000001700f3180 0x00000001700f3180 applePayController PKPaymentAuthorizationViewController! nil None

Then the app crashes and I get this error message

function signature specialization of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2) -> 0x100581474 <+44>: brk #0x1

Can someone help me figure out how to resolve this issue. Here is my code

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)
}

}

Aucun commentaire:

Enregistrer un commentaire