Alamofire / AlamofireImage

AlamofireImage is an image component library for Alamofire
MIT License
3.99k stars 523 forks source link

Creash: specialized Dictionary._Variant.setValue(_:forKey:) #418

Closed MeiYuLong closed 4 years ago

MeiYuLong commented 4 years ago

Excuse me for bad english!

Alamofire Environment

Alamofire version:4.7.3 Xcode version:11.4 Swift version:4

Project code

http request ` public func FE_Request(with identifier: String, urlString: String, method: HTTPMethod = .get, parameters: Parameters?, success: @escaping ResultHandler, failure: @escaping ResultHandler) -> URLSessionTask? {

        if let task = self.caches[identifier] {
            failure(["message":"This request is exist, Please wait a moment","code":NSURLErrorCancelled])
            return task
        }
        print("urlString=" + urlString)
        if let p = parameters {
            FELogDebug("parameters=\(p)")
        }
        let mesage = NSLocalizedString("translate.1x", comment: "请求链接不能为空!")
        assert(!urlString.isEmpty, mesage)
        var headers: HTTPHeaders = [
            "Accept": "application/json,image/*",
            "Cache-Control": "no-cache",
            "Content-type": "application/json"
        ]
        headers["User-Agent"] = self.userAgent;
        headers["X-DEVICE-ID"] = UIDevice.IDFV;
        if let language = feUD.string(forKey: FELanguageKey), !language.isEmpty {
            var acceptLanguage = language
            if let regionCode = Locale.current.regionCode {
                acceptLanguage = "\(language)-\(regionCode)"
            }
            headers["Accept-Language"] = acceptLanguage
        }
        if let loginInfo = FELauncher.sharedInstance.getLoginInfo() { 
            if loginInfo.customerType == .Enterprise {
                headers["X-KA-SESSION-ID"] = loginInfo.sessionID
            }else if loginInfo.customerType == .Personal {
                headers["X-FLE-SESSION-ID"] = loginInfo.sessionID
            }
        }
        let dataRequest = Alamofire.request(urlString,
                                            method: method,
                                            parameters: parameters,
                                            encoding: JSONEncoding.`default`,
                                            headers: headers)
            .responseJSON { [weak self](jsonResponse) in
                if let statusCode = jsonResponse.response?.statusCode {
                    if let json = jsonResponse.value {
                        if statusCode >= 200 && statusCode < 300 {
                            //successed
                            success(json)
                        }else {
                            //failure
                            failure(json)
                        }
                    }else{
                        failure(["message":"invalid json"])
                    }
                }else{
                    if let responseError = jsonResponse.error {
                        let error = responseError as NSError
                        print(error)
                        if error.code != NSURLErrorCancelled {
                            failure(["message":error.localizedDescription,"code":error.code])
                        }
                    }else {
                        //error
                        failure(["message":"Request Error!"])
                    }
                }
                self?.caches.removeValue(forKey: identifier)
    }

    if let task = dataRequest.task {
        self.caches[identifier] = task
    }
    return dataRequest.task
}`

it‘s old problem of this crash ,Only occasionally in crash log!And i often receive another crash log “specialized dictionary.subscript.getter” at the same method .Will this be a thread problem?I'm troubled. Thank you for taking care of this.

jshier commented 4 years ago

If this is still an issue please report a new issue with a crash log. But I recommend updating Alamofire and AlamofireImage, as well as Xcode to see if it still occurs.

Tliens commented 3 years ago

why?someone told me