나는 구독 IAP에서 작업하고 있습니다. 나는 모든 구매를 세웠다. 그들의 세부 사항은 잘 돌아 왔고, 나는 샌드 박스에서 구매를 할 수 있으며, 모든 메시지를 괜찮게 얻을 수있다. 내가 지금 가지고있는 문제는 영수증을 확인하는 것이다. 나는 항상 URL을 반환하지만, 읽으려고하면 파일이 존재하지 않는다는 오류가 계속 발생합니다. 그래서 시도하고 새로 고침 SKReceiptRefreshRequest
. 여전히 동일하게 다시 시도하십시오.영수증 인증 iOS - 해당 파일이 없기 때문에 파일을 열 수 없습니다.
시뮬레이터 및 두 개의 실제 장치에서 응용 프로그램을 제거 했으므로 새로운 설치 및 동일한 문제에서 다시 시도하십시오. 내가 깨달은 한가지, 실제 장치 중 하나는 [샌드 박스] 언급과 함께 암호 프롬프트 요청을 표시합니다. 그러나 두 가지 프롬프트 (암호 수락 포함) 후에는 구매가 완료되지 않고 "사용자/암호가 일치하지 않음"메시지가 나타납니다. 시뮬레이터에서 itunes 계정과 암호를 묻는 메시지가 나오면 모두 통과하지만 실제 구입 확인은 오지 않습니다 (4 분, 안정적인 인터넷 연결을 기다렸습니다).
이 검증 과정은
let receiptURL = Bundle.main.appStoreReceiptURL
func receiptValidation() {
print("1")
print("2", receiptURL)
do {
print("3")
let receiptData = try Data(contentsOf: receiptURL!, options: .alwaysMapped)
print(receiptData)
let receiptString = receiptData.base64EncodedString(options: [])
let dict = ["receipt-data" : receiptString, "password" : "\(password)"] as [String : Any]
do {
print("4")
let jsonData = try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)
if let sandboxURL = Foundation.URL(string:"https://sandbox.itunes.apple.com/verifyReceipt") {
print("5")
var request = URLRequest(url: sandboxURL)
request.httpMethod = "POST"
request.httpBody = jsonData
let session = URLSession(configuration: URLSessionConfiguration.default)
let task = session.dataTask(with: request) { data, response, error in
print("6")
if let receivedData = data,
let httpResponse = response as? HTTPURLResponse,
error == nil,
httpResponse.statusCode == 200 {
print("7")
do {
print("8")
if let jsonResponse = try JSONSerialization.jsonObject(with: receivedData, options: JSONSerialization.ReadingOptions.mutableContainers) as? Dictionary<String, AnyObject> {
print(jsonResponse, jsonResponse.count)
// parse and verify the required informatin in the jsonResponse
} else { print("Failed to cast serialized JSON to Dictionary<String, AnyObject>") }
}
catch { print("Couldn't serialize JSON with error: " + error.localizedDescription) }
}
}
print("51")
task.resume()
} else { print("Couldn't convert string into URL. Check for special characters.") }
}
catch { print("Couldn't create JSON with error: " + error.localizedDescription) }
}
catch {
let appReceiptRefreshRequest = SKReceiptRefreshRequest(receiptProperties: nil)
appReceiptRefreshRequest.delegate = self
appReceiptRefreshRequest.start()
print("Couldn't read receipt data with error: " + error.localizedDescription) }
}
func requestDidFinish(_ request: SKRequest) {
print("???")
do {
let receipt = try Data(contentsOf: receiptURL!) //force unwrap is safe here, control can't land here if receiptURL is nil
print(receipt)
} catch {
print("WTF NO RECEIPT")
// still no receipt, possible but unlikely to occur since this is the "success" delegate method
}
}
그리고이 응용 프로그램을 실행 한 디버깅 출력 (I 다른 자습서 및 다른 사람의 문제에서, 꽤 많은 시간을 변경). receiptURL은 시뮬레이터/실제 장치 사이에서 다르지만 그 밖의 모든 것은 동일하게 유지됩니다.
1
2 Optional(file:///Users/apple/Library/Developer/CoreSimulator/Devices/47EA3293-9B13-4808-BD0B-13D884D14BFE/data/Containers/Data/Application/2F1B7E4E-C523-4270-BF46-6D77F7A2220C/StoreKit/receipt)
3
Couldn't read receipt data with error: The file “receipt” couldn’t be opened because there is no such file.
???
WTF NO RECEIPT
???
WTF NO RECEIPT
영수증을 생성하거나 찾을 수없는 이유는 무엇입니까? 장치 문제입니까, 버그입니까, 아니면 뭔가 모르는가요?
결제가 완료되면 거래가 발생합니다. 구매 한 영수증을 다운로드해야합니까? 영수증은 구매 시점에 자동으로 다운로드됩니다. 그럼에도 불구하고 SKReceiptRefreshRequest가 작동하지 않고 appStoreReceiptURL을 할당 할 때마다 읽기 시간에 실패하는 이유는 무엇입니까? –