2017-08-16 29 views
0

我已經將crashlytics集成到我的iOS應用程序中。我得到了這樣的崩潰日誌瞭解織物的碰撞記錄

# Issue #: 1 
# Issue ID: 59940bb4be077a4dcc2837ff 
# Session ID: 
e68dd53b640d4ac39f21b511a9f78b78_90910b25826211e7a25d56847afe9799_0_v2 
# Date: 2017-08-16T06:30:00Z 
# OS Version: 10.3.3 (14G60) 
# Device: iPhone 6s 
# RAM Free: 3.8% 
# Disk Free: 15.2% 

#0. Crashed: com.apple.main-thread 
0 MY APP       0x100086b50 specialized static Functions.retunDateStringFromDateString(dateString : String, inuputFormat : String, outPutFormat : String) -> String (Functions.swift:123) 
1 MY APP       0x1000ef820 specialized TeamAttendanceViewController.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (Functions.swift) 
2 MY APP       0x1000eaa78 @objc TeamAttendanceViewController.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell (TeamAttendanceViewController.swift) 
3 UIKit       0x193641d90 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 688 
4 UIKit       0x193641fa8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80 
5 UIKit       0x19362f6ac -[UITableView _updateVisibleCellsNow:isRecursive:] + 2152 
6 UIKit       0x193646f98 -[UITableView _performWithCachedTraitCollection:] + 120 
7 UIKit       0x1933df49c -[UITableView layoutSubviews] + 176 
8 UIKit       0x1932f9cc0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200 
9 QuartzCore      0x1904ea274 -[CALayer layoutSublayers] + 148 
10 QuartzCore      0x1904dede8 
CA::Layer::layout_if_needed(CA::Transaction*) + 292 
11 QuartzCore      0x1904deca8 
CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32 
12 QuartzCore      0x19045a34c 
CA::Context::commit_transaction(CA::Transaction*) + 252 
13 QuartzCore      0x1904813ac 
CA::Transaction::commit() + 504 
14 QuartzCore      0x190481e78 
CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned 
long, void*) + 120 
15 CoreFoundation     0x18d1789a8 
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32 
16 CoreFoundation     0x18d176630 __CFRunLoopDoObservers 
+ 372 
17 CoreFoundation     0x18d176a7c __CFRunLoopRun + 956 
18 CoreFoundation     0x18d0a6da4 CFRunLoopRunSpecific + 
424 
19 GraphicsServices    0x18eb11074 GSEventRunModal + 100 
20 UIKit       0x193361c9c UIApplicationMain + 208 
21 MY APP       0x10002f710 main 
(AppDelegate.swift:16) 
22 libdyld.dylib     0x18c0b559c start + 4 

這是我第一次讀取崩潰日誌文件。我認爲。我的Function課程的returnDateString方法的123行有問題。但是,我怎麼能理解這條線的確切問題?這是我在Function類中的方法。

class func retunDateStringFromDateString(dateString : String,inuputFormat: String, outPutFormat : String) -> String{ 
    if(dateString != ""){ 
     let dateFormatter = DateFormatter() 
     dateFormatter.dateFormat = inuputFormat//this your string date format 

     let date = dateFormatter.date(from: dateString) 


     dateFormatter.dateFormat = outPutFormat///this is what you want to convert format 

     let timeStamp = dateFormatter.string(from: date!) 


     return timeStamp 
    }else{ 
     return "" 
    } 

} 

這是我的123行。 let timeStamp = dateFormatter.string(from: date!)

這是什麼原因? 請幫幫我。 感謝

UPDATE

var inTimeArray = inTime?.components(separatedBy: ".") 
print(inTimeArray) 

cell.inOneTime.text = Functions.nullToNilForString(value: Functions.retunDateStringFromDateString(dateString: (inTimeArray?[0])! ,inuputFormat: "yyyy-MM-dd'T'HH:mm:ss", outPutFormat: "HH:mm") as AnyObject?)?.description 
+1

可能重複的[DateFormatter不會返回日期爲「HH:mm:ss」](https://stackoverflow.com/questions/40692378/dateformatter-doesnt-return-date-for-hhmmss) – the4kman

+1

您最在'date'中可能有'nil'。什麼是'inputFormat'和什麼是'dateString'?除非你是100%,否則不要使用強制解包,這個值永遠不會爲零。至於理解崩潰日誌,崩潰日誌只顯示堆棧跟蹤,他們不能告訴你問題的確切原因,因爲在發佈模式下,你的應用程序不在調試器中運行,因此不會有任何斷點來捕獲和識別運行時異常。但是,正如您在此處所做的那樣,您可以在大多數情況下找出導致錯誤的線路的錯誤。 –

+0

@DávidPásztor我更新了我的問題與調用線 – user1960169

回答

2

基於對意見的討論,似乎本地設置你的用戶的不同設備而不是您的測試設備和不同的語言環境會在使用明確的日期格式時造成麻煩。

正如我已經在評論中指出的那樣,不要強制打開日期值,而是使用可選的解包並向用戶顯示錯誤消息,如果dateFormatter.date(from: String)失敗。

您應該將dateFormat更改爲獨立於語言環境的格式,或者設置dateFormatter.locale = Locale(identifier: "en_US_POSIX")或您已測試明確日期格式的任何其他語言環境。

至於理解crashlog,崩潰日誌只顯示堆棧跟蹤,他們不能告訴你麻煩的確切原因,因爲在發佈模式下,你的應用程序沒有在調試器中運行,因此可能沒有斷點來捕獲和識別運行時異常。但是,正如您在此處所做的那樣,您可以在大多數情況下找出導致錯誤的線路的錯誤。

+0

非常感謝。如果我設置了dateFormatter.locale = Locale(標識符:「en_US_POSIX」),它是否適用於任何設備中的任何其他語言環境設置? – user1960169

+1

這取決於你的'dateString'來自哪裏。如果它是獨立於設備的值,那麼是的,將語言環境設置爲美國將在每個設備上獨立於區域設置而工作。 –

+0

有沒有什麼辦法可以在我的設備中發現同樣的問題? – user1960169

1

這裏最有可能的問題是,你有力量展開您的可選日期參數。如果無法將dateString解析爲日期,則日期將爲零,並強制解包將導致崩潰。

嘗試這樣的事情,而不是:

guard let date = dateFormatter.date(from: dateString) else { 
    // handle the error 
    return "" 
} 
//... 
return dateFormatter.string(from: date) 

查看自選的文檔,以獲得更好的理解https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html