我们的最新版本导致1%的用户基础崩溃。我完全坚持使用它,因为它不能在我们的暂存环境中复制。
Firebase Crashlytics抛出此错误:
Crashed: NSOperationQueue 0x282d76da0 (QOS: UNSPECIFIED)
0 MyApp 0x102d38c40 String.toExpiryDate() + 339 (Extensions.swift:339)
1 MyApp 0x102d3f628 closure #1 in ApiService.unlockVariablePass(credit:complete:) + 235 (ApiService.swift:235)
2 MyApp 0x102d34324 partial apply for closure #1 in HttpClient.post(url:token:username:password:body:callback:) + 53 (HttpClientService.swift:53)
3 MyApp 0x102d693e0 partial apply for closure #1 in NSURLSession.dataTask(with:completionHandler:) + 20 (URLSessionProtocol.swift:20)
4 MyApp 0x102d69210 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () (<compiler-generated>)
5 CFNetwork 0x1936f1688 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 32
6 CFNetwork 0x193705220 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 176
7 Foundation 0x193b81ef8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
8 Foundation 0x193a8e3e0 -[NSBlockOperation main] + 72
9 Foundation 0x193a8d8c8 -[__NSOperationInternal _start:] + 740
10 Foundation 0x193b83c7c __NSOQSchedule_f + 272
我已经检查了服务器,并且日志证明始终以正确的格式提供expiry_date。它从来没有为空。
{"expiry_date": "2019-07-05 20:00:36"}
客户端代码:
try? self.httpClient.post(url: url, token: ServerUrlFabric.shared.getTokenForAPI(), username: kc_username, password: kc_password, body: creditDict) { (data, response, error) in
if let error = error {
log(error.localizedDescription)
complete(false, nil, ServiceError.invalidSession)
} else if let httpResponse = response as? HTTPURLResponse {
switch (httpResponse.statusCode) {
case 201:
let json = try! JSONSerialization.jsonObject(with: data!, options: []) as! Dictionary<String, Any>
let expiryDate = (json["expiry_date"] as! String).toExpiryDate()
complete(true, expiryDate, nil)
扩展名:
extension String {
func toExpiryDate() -> Date {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
formatter.timeZone = TimeZone(abbreviation: "UTC")
return formatter.date(from: self)!
}
}
请问我错过了什么?