我有一個奇怪的情況,我的應用程式在測驗中加載它的應用程式商店視圖很好,包括通過 testflight,但是當從應用程式商店下載時它崩潰了。我在下面找到了相關的崩潰日志,但我不確定哪些部分與我的代碼相關,而不是幕后發生的事情。
這是堆疊跟蹤:
Thread 4 Crashed:
0 My app 0x00000001001b7908 Swift runtime failure: Index out of range 0 (<compiler-generated>:0)
1 My app 0x00000001001b7908 subscript.get 20 (<compiler-generated>:0)
2 My app 0x00000001001b7908 specialized Store.productsRequest(_:didReceive:) 1376
3 My app 0x00000001001b75e8 list.get 28 (Store.swift:0)
4 My app 0x00000001001b75e8 specialized Store.productsRequest(_:didReceive:) 576
5 My app 0x00000001001b5d8c productsRequest 12 (<compiler-generated>:0)
6 My app 0x00000001001b5d8c @objc Store.productsRequest(_:didReceive:) 76
7 StoreKit 0x00000001ab0f8070 __27-[SKProductsRequest _start]_block_invoke_2 136 (SKProductsRequest.m:104)
8 libdispatch.dylib 0x000000018f5404b4 _dispatch_call_block_and_release 32 (init.c:1518)
9 libdispatch.dylib 0x000000018f541fdc _dispatch_client_callout 20 (object.m:560)
10 libdispatch.dylib 0x000000018f5450c8 _dispatch_queue_override_invoke 788 (inline_internal.h:2632)
11 libdispatch.dylib 0x000000018f553a6c _dispatch_root_queue_drain 396 (inline_internal.h:0)
12 libdispatch.dylib 0x000000018f554284 _dispatch_worker_thread2 164 (queue.c:7052)
13 libsystem_pthread.dylib 0x00000001d49e4dbc _pthread_wqthread 228 (pthread.c:2631)
14 libsystem_pthread.dylib 0x00000001d49e4b98 start_wqthread 8
從這里我讀到對 productsRequest 的呼叫有問題所以這里是這個函式:
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let myProduct = response.products
for product in myProduct {
list.append(product)
}
// Update labels
localTitle = list[0].localizedTitle
localDescription = list[0].localizedDescription
// Format the price and display
let formatter = NumberFormatter()
formatter.locale = Locale.current
formatter.numberStyle = .currency
if let formattedPrice = formatter.string(from: list[0].price){
localPrice = ("Upgrade: \(formattedPrice)")
delegate?.storeUpdateReceived(store: self)
}
}
這是我不確定的。我們能否確定該功能的問題所在?還是在我們真正進入函式中的行之前就觸發了問題?我無法在實時環境之外重現崩潰,所以我認為我不能在實時安裝的應用程式中添加斷點。
我看到索引超出范圍錯誤,但這可能是由于我在串列中參考第一個元素的位置(可能是空的)引起的嗎?或者那個索引可能是別的東西?
uj5u.com熱心網友回復:
根據可用資訊,我們可以假設它在您參考串列的第一個元素的行上崩潰。如果串列為空,它肯定會崩潰,你可以這樣寫:
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let myProduct = response.products
for product in myProduct {
list.append(product)
}
// Update labels
localTitle = list.first?.localizedTitle ?? ""
localDescription = list.first?.localizedDescription ?? ""
// Format the price and display
let formatter = NumberFormatter()
formatter.locale = Locale.current
formatter.numberStyle = .currency
if let price = list.first?.price, let formattedPrice = formatter.string(from: price){
localPrice = ("Upgrade: \(formattedPrice)")
delegate?.storeUpdateReceived(store: self)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529567.html
