我正在尝试让订阅正常工作。我的收据验证在沙盒模式下工作,但是当我使用实时 url 进行收据验证时它还不起作用。这是我的代码:
func receiptValidation() {
// appStoreReceiptURL still says sandboxReceipt
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
do {
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
let receiptString = receiptData.base64EncodedString(options: [])
let dict = ["receipt-data" : receiptString, "password" : iTunesMasterAppSecret] as [String : Any]
do {
let jsonData = try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
var receiptUrl:String
if (liveMode) {
receiptUrl = "https://buy.itunes.apple.com/verifyReceipt"
}
else {
receiptUrl = "https://sandbox.itunes.apple.com/verifyReceipt"
}
// appStoreReceiptURL still says sandboxReceipt
if let sandboxURL = Foundation.URL(string:receiptUrl) {
var request = URLRequest(url: sandboxURL)
request.httpMethod = "POST"
request.httpBody = jsonData
let session = URLSession(configuration: URLSessionConfiguration.default)
let task = session.dataTask(with: request) {
if let receivedData = data,
let httpResponse = response as? HTTPURLResponse,
error == nil,
httpResponse.statusCode == 200 {
do {
if let jsonResponse = try JSONSerialization.jsonObject(with: receivedData, options: JSONSerialization.ReadingOptions.mutableContainers) as? Dictionary<String, AnyObject>
当我得到 jsonResponse 时,我得到 "[\"status\": 21007]",它在 Apple 文档中被描述为:
21007 -- This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.
有人可以帮我让订阅进入实时模式吗?