Implementing Receipt Validation in Swift 3

后端 未结 6 742
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 09:59

I am developing an iOS app in Swift 3 and trying to implement receipt validation following this tutorial: http://savvyapps.com/blog/how-setup-test-auto-renewable-subscriptio

6条回答
  •  长情又很酷
    2020-12-24 10:34

    I struggled my head with the same problem. The issue is that this line:

    let receiptString = receiptData?.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
    

    Returns an OPTIONAL and

    jsonData = try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
    

    cannot handle optionals. So to fix it, simply substitute the first line of code with this:

    let receiptString:String = receiptData?.base64EncodedString(options: NSData.Base64EncodingOptions.lineLength64Characters) as String!
    

    And everything will work like charm!

提交回复
热议问题