首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >SessionDelegate.urlSession崩溃(_:task:didCompleteWithError :)

SessionDelegate.urlSession崩溃(_:task:didCompleteWithError :)
EN

Stack Overflow用户
提问于 2019-05-30 01:47:55
回答 1查看 0关注 0票数 0

当我在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

EN

回答 1

Stack Overflow用户

发布于 2019-05-30 11:13:53

你在self.getHeader()中传递了什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档