2017-08-16 27 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