Sto lavorando al trasferimento del mio progetto da AFNetworking ad Alamofire. Piace molto il progetto. Tuttavia, sto ricevendo questo errore quando tento di fare una richiesta GET.Alamofire Errore di richiesta: NSURLErrorDomain Code -1005 La connessione di rete è stata persa
Ecco qualche esempio di codice:
class func listCloudCredntials(onlyNew onlyNew: Bool = true, includePending: Bool = true) -> Request {
let parameters: [String: AnyObject] = includePending ? ["include_pending": "true"] : [:]
let urlString = "https://myapp-staging.herokuapp.com/api/1/credntials"
let token = SSKeychain.storedToken()
let headers: [String: String] = ["Authorization": "Bearer \(token)"]
return Alamofire.request(.GET, urlString, parameters: parameters, encoding: .JSON, headers: headers)
}
Poi, nel mio VC:
listCloudCredntials().validate().responseJSON() {
(response: Response<AnyObject, NSError>) in
switch response.result {
case .Success(let result):
printCR("success: \(result)")
case .Failure(let error):
printCR("error: \(error)")
}
}
Ecco l'errore che sto funzionando in:
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x14e9c77f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey= https://myapp-staging.herokuapp.com/api/1/credntials , NSErrorFailingURLKey= https://myapp-staging.herokuapp.com/api/1/credntials , _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.}
ho provato a fare funzionare su iOS Simulator con 1OS 8.4 e iOS 9.1, oltre al mio iPhone 6S con iOS 9.1.
Cosa sto sbagliando?
-------- -------- EDIT
Per chiarire, questa funzione funziona bene con AFNetworking.
Ecco il risultato debugprint (richiesta) (si tratta di una richiesta GET):
$ curl -i \
-H "Authorization: Bearer some-JWT-Security-Token" \
-H "Content-Type: application/json" \
-H "Accept-Language: en-US;q=1.0" \
-H "Accept-Encoding: gzip;q=1.0,compress;q=0.5" \
-H "User-Agent: Company/com.Company.AppName (1081; OS Version 9.2 (Build 13C75))" \
-d "{\"include_pending\":\"true\"}" \
"https://appname-staging.herokuapp.com/api/1/credntials"
devo cambiare ricciolo -i arricciare -X mettersi in ordine per il ricciolo di tornare con successo.
Ecco un'altra chiamata che devo fare nell'app che funziona senza problemi.
curl -i \
-X POST \
-H "Content-Type: application/json" \
-H "Accept-Language: en-US;q=1.0" \
-H "Accept-Encoding: gzip;q=1.0,compress;q=0.5" \
-H "User-Agent: Company/com.Company.AppName (1081; OS Version 9.2 (Build 13C75))" \
-d "{\"token\":\"UserSessionTokenString\"}" \
"https://appname-staging.herokuapp.com/api/1/authenticate/user"
Potrebbe essere qualcosa con GET vs POST?
Possibile duplicato di [Dominio errore = NSURLErrorDomain Code = -1005 "La connessione di rete è stata persa."] (Http://stackoverflow.com/questions/25372318/error-domain-nsurlerrordomain-code- 1005-the-network-connection-was-lost) – sunshinejr