сбой в SessionDelegate.urlSession (_: task: didCompleteWithError :) - PullRequest
0 голосов
/ 29 мая 2019

У меня происходит сбой внутри класса SessionManager alamofire, когда я выполняю вызов API в appDelegate:

Код 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 Foundation
- [NSNotificationCenter postNotificationName: object: userInfo:] + 68 19 Alamofire
Запрос.swift строка 205 Request.resume () 20 Alamofire
SessionManager.swift строка 265 SessionManager.request ( :) 21 Alamofire
SessionManager.swift строка 239 SessionManager.request (
: метод: параметры:кодировка: заголовки :) 22 Alamofire
Alamofire.swift строка 140 запроса (: метод: параметры: кодировка: заголовки :) 23 myapp
RequestManager.swift строка 3538 статический RequestManager.isCurrentVersionValid (
:)24 myapp
строка AppDelegate.swift 96 специализированных AppDelegate.application (: didFinishLaunchingWithOptions :) 25 myapp
строка 0 @objc AppDelegate.application (
: didFinishLaunchingWithOptions :) 26 UIKitCore * 10pp_handleDelegateCallbacksWithOptions: isSuspended: restoreState:] + 412 55 UIKitCore
UIApplicationMain + 212 56 myapp
APaymentCard.swift line 25 main 57 libdyld.dylib
start + 4

...