【发布时间】:2015-03-12 05:47:24
【问题描述】:
我发布了我的游戏更新,我认为它可以修复 IAP 的收据验证问题。
这在我的开发环境中运行良好,但如果您从应用商店下载该应用,它会在启动时崩溃。我查看了设备上的崩溃报告,但我无法准确判断我犯了哪个错误,因为如果我从我的计算机构建,这一切都很完美。非常令人沮丧的是,当我的应用程序在启动时崩溃时,Apple 会接受我的更新!
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 3
Last Exception Backtrace:
0 CoreFoundation 0x1845a259c __exceptionPreprocess + 132
1 libobjc.A.dylib 0x194cf40e4 objc_exception_throw + 60
2 CoreFoundation 0x184487904 -[__NSArrayI objectAtIndex:] + 224
3 Kill Sector 0x1000b3714 0x10001c000 + 620308
4 CFNetwork 0x183f8af34 __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 188
5 Foundation 0x18545b4a8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
6 Foundation 0x1853acc34 -[NSBlockOperation main] + 96
7 Foundation 0x18539c5bc -[__NSOperationInternal _start:] + 636
8 Foundation 0x18545e20c __NSOQSchedule_f + 228
9 libdispatch.dylib 0x19533936c _dispatch_client_callout + 16
10 libdispatch.dylib 0x1953434c0 _dispatch_queue_drain + 1216
11 libdispatch.dylib 0x19533c474 _dispatch_queue_invoke + 132
12 libdispatch.dylib 0x195345224 _dispatch_root_queue_drain + 664
13 libdispatch.dylib 0x19534675c _dispatch_worker_thread3 + 108
14 libsystem_pthread.dylib 0x1955152e4 _pthread_wqthread + 816
15 libsystem_pthread.dylib 0x195514fa8 start_wqthread + 4
这是我的支票收据代码:
func checkReceipt(){
var appStoreURL = "https://buy.itunes.apple.com/verifyReceipt"
#if DEBUG
appStoreURL = "https://sandbox.itunes.apple.com/verifyReceipt"
#endif
var appStoreStatusZero = false // we connected to correct app store
if let url = NSBundle.mainBundle().appStoreReceiptURL {
if let receipt = NSData(contentsOfURL: url) {
var error: NSError?
let requestContents = ["receipt-data": receipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))]
let requestData = NSJSONSerialization.dataWithJSONObject(requestContents, options: NSJSONWritingOptions(rawValue: 0), error: &error)
if requestData == nil {
println("not receiving request Data")
}
let storeURL = NSURL(string: appStoreURL)
let storeRequest = NSMutableURLRequest(URL: storeURL!)
storeRequest.HTTPMethod = "POST"
storeRequest.HTTPBody = requestData
let queue = NSOperationQueue()
NSURLConnection.sendAsynchronousRequest(storeRequest, queue: queue, completionHandler: {
response, data, error in
if error != nil {
println("connection error")
return
} else {
var error: NSError?
let jsonResponse = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0), error: &error) as NSDictionary?
if jsonResponse == nil {
println("json error")
return
} else {
var receiptInfo = jsonResponse?.objectForKey("receipt") as NSDictionary?
var inAppInfo = receiptInfo?.objectForKey("in_app") as NSArray?
var thisIAPInfo = inAppInfo?.objectAtIndex(0) as NSDictionary?
var removeAdsID = thisIAPInfo?.objectForKey("product_id") as String?
if removeAdsID == self.productID {
self.adsRemoved = true
}
}
}
})
}
}
}
我在这里做的有什么明显的错误吗?我不知道哪里出错了。
有没有办法像在应用商店中一样测试它?我已经尝试过临时部署,但我的应用程序可以正常工作。在无法测试的情况下很难判断我是否正在修复错误!
【问题讨论】:
-
您现在是否遇到过这些崩溃?或者这些是昨天的崩溃日志?因为 App Store 是 down yesterday,这可能会造成这些问题。
-
我现在遇到了这些崩溃。
-
问题似乎是您的
NSArray。 -
我也是这么想的。看着这个developer.apple.com/library/ios/releasenotes/General/… 似乎“in_app”应该是一个数组 IAP 收据。也许 thisIAPInfo 崩溃是因为它是一个空数组?我在沙箱中测试了很多次,JSON 结构在生产中会有所不同吗?
-
如果用户从未进行过应用内购买,有多少应用内购买收据?可能为零,即空数组。如果用户没有进行任何 IAP,是否会调用此代码?
标签: ios swift in-app-purchase app-store