ios - 验证收据 iOS

标签 ios swift

看起来苹果本月正在进行任何类型的更新......最近我的应用程序被拒绝并显示此消息

When validating receipts on your server, your server needs to be able to handle a production-signed app getting its receipts from Apple’s test environment. The recommended approach is for your production server to always validate receipts against the production App Store first. If validation fails with the error code "Sandbox receipt used in production," you should validate against the test environment instead.

我的应用程序之前已获得批准...这是我正在使用的代码

  //Sandbox URL
       //let url = URL(string: "https://sandbox.itunes.apple.com/verifyReceipt")!
        let url = URL(string: "https://buy.itunes.apple.com/verifyReceipt")!

    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.httpBody = bodyData

    let task = URLSession.shared.dataTask(with: request) { (responseData, response, error) in
        if let error = error {
            completion(.failure(.other(error)))
        } else if let responseData = responseData {
            let json = try! JSONSerialization.jsonObject(with: responseData, options: []) as! Dictionary<String, Any>
            //print(json)
            let session = Session(receiptData: data, parsedReceipt: json)
            self.sessions[session.id] = session
            let result = (sessionId: session.id, currentSubscription: session.currentSubscription)
            completion(.success(result))
        }
    }

    task.resume()
}

最佳答案

您不必使用服务器。如果需要,您可以在客户端上验证它。或者,如果您愿意,您可以完全放弃任何验证(不推荐)。

您收到的拒绝很可能是因为这一次,他们使用了测试环境来验证 IAP。

他们的documentation

If you are doing receipt validation, be sure to verify your receipt with the production URL (https://buy.itunes.apple.com/verifyReceipt) first. This applies even in the case where your app is used in the sandbox environment. App Review will review the production version of your app in the sandbox. When your app processes the receipt, it must be capable of detecting the 21007 receipt status code and sending the receipt to the sandbox receipt validation server (https://sandbox.itunes.apple.com/verifyReceipt). Once your app is approved and running in the production environment, sending the receipt to the production server first is the correct action.

请注意,他们没有指定收据验证在哪里完成。

您的代码缺少的是沙箱的回退。这就是为什么他们这次拒绝了你。

关于ios - 验证收据 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54917474/

相关文章:

ios - 如何使用 Alamofire 下载文件?

ios - 何时通过 xib 创建 View 以及何时通过代码创建 View ?

ios - 如何永久更改 Meteor Cordova 中的 iOS 应用程序配置?

ios - 内联首选日期选择器样式未正确呈现月份和工作日

ios - 将 Storyboard 元素关联到类中已定义的导出和操作

ios - 如何自动为 Swift 类创建初始化程序?

ios - 尝试直接转到数组末尾时发生索引超出范围错误

ios - AVCamPreviewView 初始化缓慢,有时会在关闭/重新打开 View 后导致崩溃 - 使用 AVCam 示例项目

ios - 将日期转换为 GMT 时间 Day Date Month Year Swift

ios - 应用多个 CAGradientLayer 来 mask View