使用Crashlytics错误日志修复崩溃

时间:2018-03-02 23:25:48

标签: swift logging crash report crashlytics

我从Crashlytics获得了一个错误日志,内容如下:

books = {}
books["auth1"] = {}
books["auth2"] = {}
books["auth1"]["humor"] = 20
books["auth1"]["action"] = 30
books["auth2"]["comedy"] = 20

pd.DataFrame.from_dict(books, orient='columns', dtype=None)

Crashed: NSOperationQueue 0x1d003d5a0 (QOS: UNSPECIFIED) 0 (App Name) 0x100710fa4 specialized ViewController.(getHistoricalData(url : String, currency : String) -> ()).(closure #1) (ViewController.swift:1324) 1 (App Name) 0x1007029f8 ViewController.(getHistoricalData(url : String, currency : String) -> ()).(closure #1) (ViewController.swift) 2 (App Name) 0x100712178 partial apply for ViewController.(getHistoricalData(url : String, currency : String) -> ()).(closure #1) (ViewController.swift) 3 (App Name) 0x1006fd448 @callee_owned (@owned Data?, @owned URLResponse?, @owned Error?) -> ()NSData?NSData (ViewController.swift) 4 CFNetwork 0x181fd1d68 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 32 5 CFNetwork 0x181fea6bc __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 152 6 Foundation 0x18241dba0 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16 7 Foundation 0x18235d894 -[NSBlockOperation main] + 72 8 Foundation 0x18234d4c4 -[__NSOperationInternal _start:] + 848 9 libdispatch.dylib 0x1813c6a14 _dispatch_client_callout + 16 10 libdispatch.dylib 0x1814029c4 _dispatch_block_invoke_direct$VARIANT$armv81 + 280 11 libdispatch.dylib 0x1813c6a14 _dispatch_client_callout + 16 12 libdispatch.dylib 0x1814029c4 _dispatch_block_invoke_direct$VARIANT$armv81 + 280 13 libdispatch.dylib 0x181402878 dispatch_block_perform$VARIANT$armv81 + 104 14 Foundation 0x18241f878 __NSOQSchedule_f + 376 15 libdispatch.dylib 0x1813c6a14 _dispatch_client_callout + 16 16 libdispatch.dylib 0x181403640 _dispatch_continuation_pop$VARIANT$armv81 + 420 17 libdispatch.dylib 0x181401fe8 _dispatch_async_redirect_invoke$VARIANT$armv81 + 596 18 libdispatch.dylib 0x1814082a4 _dispatch_root_queue_drain + 568 19 libdispatch.dylib 0x181408008 _dispatch_worker_thread3 + 112 20 libsystem_pthread.dylib 0x18166f06c _pthread_wqthread + 1268 21 libsystem_pthread.dylib 0x18166eb6c start_wqthread + 4 对应我应用的名称。据我所知,错误发生在ViewController.swift的第1324行,在函数(App Name)中。 这个功能如下:

getHistoricalData(url : String, currency : String)

第1324行对应func getHistoricalData(url: String, currency: String){ var Currenturl = NSURL(string: url) if Reachability.isConnectedToNetwork() { URLSession.shared.dataTask(with: (Currenturl as URL?)!, completionHandler: {(data, response, error) -> Void in let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSDictionary if let jsonObj = jsonObj { // do some stuff } }).resume() } }

我已经尝试了几种不同的解包方法let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSDictionary来尝试阻止此崩溃。最初我有jsonObj之类的东西,但同样的问题正在发生。

这与我解开的方式有关吗?任何想法/指针都将非常感激!

1 个答案:

答案 0 :(得分:1)

如果错误在select Table1.Id as [@Id], Table1.Nome as [@Nome], [inner].[xml] as [*] from Table1 outer apply ( select (select Table2.Id as [@Id], Table2.DataVencimento from Table2 where Table2.Table1_Id = Table1.Id for xml path('Table2'), type) as [xml] ) as [inner] inner join Table2 on Table2.Table1_Id = Table1.Id order by Table1.Id, Table2.Id for xml path('Table1'), root('ArrayOfTable1') 中,则有两个明显的错误原因:

  • let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSDictionary的演员因任何原因失败
  • 强行展开NSDictionary失败。

请勿使用data强制解包服务器接收的数据,它可能为零。请改用以下代码:

!