alamofire

Alamofire: Send JSON with Array of Dictionaries

早过忘川 提交于 2019-11-29 07:25:20
I have a data structure that looks like this in JSON: [{ "value": "1", "optionId": "be69fa23-6eca-4e1b-8c78-c01daaa43c88" }, { "value": "0", "optionId": "f75da6a9-a34c-4ff6-8070-0d27792073df" }] Basically it is an array of dictionaries. I would prefer to use the default Alamofire methods and would not like to build the request manually. Is there a way to give Alamofire my parameters and Alamofire does the rest? If I create everything by hand I get an error from the server that the send data would not be correct. var parameters = [[String:AnyObject]]() for votingOption in votingOptions{ let

Alamofire compiled with older version of Swift language (2.0) than previous files (3.0) for architecture x86_64

…衆ロ難τιáo~ 提交于 2019-11-29 07:21:18
When I move my program to the XCode8, I got this error: Alamofire compiled with older version of Swift language (2.0) than previous files (3.0) for architecture x86_64. I have update Alamofire to version 4.0, and set the Use Legacy Swift Language Version to NO. What's the matter? Update your cocoa pods and clear your derive data folder and try to run again. In xcode 8 derived data folder changed, Go to File -> Workspace setting -> then see this image, Click on -> on path and clear that derived data folder. Himanshu Mahajan Uninstall pods and install it again. Use below commands to install the

Basic Authentication with Alamofire

风流意气都作罢 提交于 2019-11-29 06:12:27
问题 Experiencing an issue when authenticating with Basic Auth. I am using a standard enum that conforms to URLRequestConvertible protocol to construct my requests. The issue is that when I manually set the authorization headers in the enum like so: let user = *** let password = *** let credentialData = "\(user):\(password)".dataUsingEncoding(NSUTF8StringEncoding)! let base64Credentials = credentialData.base64EncodedStringWithOptions([]) mutableURLRequest.setValue("Basic \(base64Credentials)",

Download File Using Alamofire 4.0 (Swift 3)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 05:32:13
问题 In older version of Alamofire. This is how I download file let destinationPath = Alamofire.Request.suggestedDownloadDestination( directory: .documentDirectory, domain: .userDomainMask); Alamofire.download(.GET, urlString, destination: destinationPath) .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in // print(totalBytesRead) } .response { request, response, _, error in let downloadedFilePath = destinationPath(URL(string: "")!, response!); NSUserDefaultsHelper.saveURL

Why does Unexpected non-void return value in void function happen? [duplicate]

白昼怎懂夜的黑 提交于 2019-11-29 05:22:13
This question already has an answer here: How to return value from Alamofire 5 answers I created a function to get URL from API, and return URL string as the result. However, Xcode gives me this error message: Unexpected non-void return value in void function Does anyone know why this happens? func getURL(name: String) -> String { let headers: HTTPHeaders = [ "Cookie": cookie "Accept": "application/json" ] let url = "https://api.google.com/" + name Alamofire.request(url, headers: headers).responseJSON {response in if((response.result.value) != nil) { let swiftyJsonVar = JSON(response.result

AlamoFire Ignore Cache-Control Headers

微笑、不失礼 提交于 2019-11-29 03:59:57
问题 Is it possible to ignore cache-control headers when performing a request/handling the response with AlamoFire? Currently I am making a request as follows, and the server is returning large cache-control headers, when in fact we need to ignore them. Alamofire.request(.GET, url).responseJSON { (_, _, result) in // Do something I know the correct solution is to modify the server response, but this is not feasible at this time. Also, there are other requests where I do want to honor the cache

Is there a way to do Alamofire requests with retries

别等时光非礼了梦想. 提交于 2019-11-29 03:49:58
I have a lot of places in the code where Alamofire request/response are handled. Each of this requests may fail because of some intermittent problem (the most common is flaky network). I would like to be able to retry requests 3 times before bailing out. The straightforward method would be to having something like that var errorCount = 0 func requestType1() { let request = Alamofire.request(...).responseJSON { response in if (isError(response) && errorCount < 3) { errorCount += 1 request1() } if (isError(response)) { handleError() } handleSuccess() } } However, I dislike this approach A LOT

How to retrieve Alamofire response header for a request

寵の児 提交于 2019-11-29 03:12:39
how can I retrieve response headers for a request? Below is a request I make. Alamofire.request(.GET, requestUrl, parameters:parameters, headers: headers) .responseJSON { response in switch response.result { case .Success(let JSON): ... case .Failure(let error): ... } Thanks in advance! If the response is type of NSHTTPURLResponse you can get header from response.allHeaderFields . So when you use Alamofire responseJSON you can access to NSHTTPURLResponse property like this : Alamofire.request(.GET, requestUrl, parameters:parameters, headers: headers).responseJSON { response in print(response

How to pass access token to Alamofire?

此生再无相见时 提交于 2019-11-29 02:59:27
问题 I am trying to pass access token in Alamofire but getting confuse in various methods around web. Below are methods which we need to use. let todosEndpoint: String = "https:url......." let headers = [ "Authorization": "Bearer \(token!)", "Content-Type": "application/X-Access-Token" ] let Auth_header = [ "Authorization" : tokenString! ] Alamofire.request(todosEndpoint, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: Auth_header) .responseJSON { response in print(

Alamofire Accept and Content-Type JSON

我是研究僧i 提交于 2019-11-29 02:52:21
问题 I'm trying to make a GET request with Alamofire in Swift. I need to set the following headers: Content-Type: application/json Accept: application/json I could hack around it and do it directly specifying the headers for the request, but I want to do it with ParameterEncoding , as is suggested in the library. So far I have this: Alamofire.request(.GET, url, encoding: .JSON) .validate() .responseJSON { (req, res, json, error) in if (error != nil) { NSLog("Error: \(error)") println(req) println