当我在appDelegate中进行api调用时,我在alamofire的SessionManager类中出现崩溃:
appDelegate代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window!.frame = UIScreen.main.bounds
...
AlamofireNetworkLogger.shared.startLogging()
AlamofireNetworkLogger.shared.level = .debug
RequestManager.isCurrentVersionValid({ (isNotValid, _) in
....
})
return true
}
RequestManager:崩溃在alamofire.request行:
class func isCurrentVersionValid( _ completion: @escaping ( _ isValid: Bool, _ error: String?) -> Void) {
let versionID = Bundle.main.infoDictionary?["CFBundleShortVersionString"]
let versionName = "ios"
let url = self.getAPIBaseURL() + "checkapplications/deprecated?sName=\(versionName)&sVersion=\((versionID!))"
Alamofire.request(url, encoding: JSONEncoding.default, headers: self.getHeader())
.validate(contentType: ["application/json"])
.responseJSON { response in
if !(Connectivity.isConnectedToInternet()) {
return
}
if response.result.error != nil {
return
}
let json = JSON(response.result.value!)
if response.result.error != nil || json["ErrorMessage"].stringValue != "" {
Crashlytics.sharedInstance().recordError(NSError(domain: (json["ErrorMessage"].stringValue), code: (response.response!.statusCode)), withAdditionalUserInfo: ["url": url, "token": self.getToken()])
completion(false, json["ErrorMessage"].stringValue)
} else {
let currentData = json["Response"].boolValue
completion(currentData, "")
}
}
}
难道我做错了什么?崩溃的痕迹是:
0(缺失) (缺失)18基础 - [NSNotificationCenter postNotificationName:object:userInfo:] + 68 19 Alamofire Request.swift line 205 Request.resume()20 Alamofire SessionManager.swift line 265 SessionManager.request(:) 21 Alamofire SessionManager。 swift line 239 SessionManager.request(:method:parameters:encoding:headers :) 22 Alamofire Alamofire.swift line 140 request(:method:parameters:encoding:headers :) 23 myapp RequestManager.swift line 3538 static RequestManager.isCurrentVersionValid( :) 24 myapp AppDelegate.swift第96行专门的AppDelegate.application(:didFinishLaunchingWithOptions :) 25 myapp 第0行@objc AppDelegate.application(:didFinishLaunchingWithOptions :) 26 UIKitCore - [UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 412 55 UIKitCore UIApplicationMain + 212 56 myapp APaymentCard.swift line 25 main 57 libdyld.dylib start + 4
发布于 2019-05-30 11:13:53
你在self.getHeader()中传递了什么?
https://stackoverflow.com/questions/-100006869
复制相似问题