IAPs eigentlich die Validierung der Quittung (Swift)

Habe ich versucht zu implementieren, Empfang Validierung in meinem spritekit Spiel. Ich habe schon nach verschiedenen Tutorials und im Grunde endete mit diesem code

enum RequestURL: String {
   case production = "https://buy.itunes.apple.com/verifyReceipt"
   case sandbox = "https://sandbox.itunes.apple.com/verifyReceipt"
   case myServer = "my server address"
}

enum ReceiptStatusCode: Int {

//Not decodable status
case unknown = -2

//No status returned
case none = -1

//valid status
case valid = 0

//The App Store could not read the JSON object you provided.
case JSONNotReadable = 21000

//The data in the receipt-data property was malformed or missing.
case malformedOrMissingData = 21002

//The receipt could not be authenticated.
case receiptCouldNotBeAuthenticated = 21003

//The shared secret you provided does not match the shared secret on file for your account.
//Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
case sharedSecretNotMatching = 21004

//The receipt server is currently not available.
case receiptServerUnavailable = 21005

//This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response.
//Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
case subscriptionExpired = 21006

// This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.
case testReceipt = 21007

//This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.
case productionEnvironment = 21008
 }

  func validateReceipt(forTransaction transaction: SKPaymentTransaction) {

    guard let receiptURL = NSBundle.mainBundle().appStoreReceiptURL else { return }

    guard let receipt = NSData(contentsOfURL: receiptURL) else { return }

    let receiptData = receipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
    let payload = ["receipt-data": receiptData]

    var receiptPayloadData: NSData?

    do {
        receiptPayloadData = try NSJSONSerialization.dataWithJSONObject(payload, options: NSJSONWritingOptions(rawValue: 0))
    }
    catch let error as NSError {
        print(error.localizedDescription)
        return
    }

    guard let payloadData = receiptPayloadData else { return }
    guard let requestURL = NSURL(string: RequestURL.sandbox.rawValue) else { return }

    let request = NSMutableURLRequest(URL: requestURL)
    request.HTTPMethod = "POST"
    request.HTTPBody = payloadData

    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { (data, response, error) in
         if let error = error {
            print(error.localizedDescription)
            return
        }  
         guard let data = data else { return }          

         do {
            let jsonData = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableLeaves) as? NSDictionary

            guard let json = jsonData else { return }

            //Correct ?
            guard let status = json["status"] as? Int where status == ReceiptStatusCode.valid.rawValue else { return }

            //Unlock product here?
            //Other checks needed?
        }

        catch let error as NSError {
            print(error.localizedDescription)
            return
        }
     }

    task.resume()
}

Es ist ziemlich boiler plate code und funktioniert wie erwartet. Mein Problem ist jetzt, dass ich weiß nicht, wie man eigentlich überprüfen der Bestätigung im letzten Schritt (markierte Linie).
Ich glaube, ich habe nun 5 oder so überprüft, die zur Validierung der Quittung. Ich habe nur keine Ahnung, wie die meisten von Ihnen gemacht werden würde in swift. Die meisten tutorials sind entweder alt, nicht enthalten diesen Schritt oder nicht, geschrieben in swift.

Wenn jemand erfolgreich nutzt Erhalt Validierung könnte mir helfen, in die richtige Richtung, es wäre sehr geschätzt werden. Vielen Dank

Update:

Nach den tollen Antworten von JSA986I und cbartel ich daraus ein Helfer auf github. Vielen Dank für die Hilfe

https://github.com/crashoverride777/SwiftyReceiptValidator

  • Sie waren in der Lage, damit es funktioniert? Wenn ja, würden Sie bitte teilen Sie Ihre fertige code. Ich Kämpfe das gleiche Problem jetzt. Vielen Dank!
  • Hey, ich habe Leider aufgegeben Erhalt Validierung für jetzt. Der obige code ist der korrekte code minus einige änderungen, die ich für den swift 2 (mit guard-Anweisungen). Nur ich verstehe nicht das Letzte bit der überprüfung, es gibt sehr wenige Anleitungen dazu.
  • Danke für die Antwort. Ich habe ein wenig Fortschritte, und teilen den code hier, wenn ich in der Lage bin, zu machen mehr Fortschritte.
Schreibe einen Kommentar