Questions tagged [alamofire]
Alamofire is an HTTP networking library written in Swift.
6,080
questions
138
votes
14
answers
228k
views
How to parse JSON response from Alamofire API in Swift?
Following code I have written and I am getting response in JSON also but the type of JSON is "AnyObject" and I am not able to convert that into Array so that I can use that.
Alamofire.request(.POST, "...
130
votes
12
answers
120k
views
Swift. Could not build objective-c module 'Alamofire'
Fresh vanilla submodule install of Alamofire, using XCode6 and following directions to a T. Something here just isn't fitting right. The error i'm getting is "Could not build objective-c module "...
127
votes
12
answers
137k
views
Swift Alamofire: How to get the HTTP response status code
I would like to retrieve the HTTP response status code (e.g. 400, 401, 403, 503, etc) for request failures (and ideally for successes too). In this code, I am performing user authentication with HTTP ...
119
votes
14
answers
220k
views
How to send a POST request with BODY in swift
I'm trying to make a post request with a body in swift using Alamofire.
my json body looks like :
{
"IdQuiz" : 102,
"IdUser" : "iosclient",
"User" : "iosclient",
"List":[
{
...
101
votes
21
answers
102k
views
Alamofire invalid value around character 0
Alamofire.request(.GET, "url").authenticate(user: "", password: "").responseJSON() {
(request, response, json, error) in
println(error)
println(json)
}
This is my request with Alamofire, ...
100
votes
11
answers
106k
views
Uploading file with parameters using Alamofire
I am attempting to upload a file using Alamofire. The upload works fine when using a File (NSUrl), however, I cant seem to figure out how to use the NSData option?
This is what I have as a test:
...
100
votes
12
answers
140k
views
POST request with a simple string in body with Alamofire
how is it possible to send a POST request with a simple string in the HTTP body with Alamofire in my iOS app?
As default Alamofire needs parameters for a request:
Alamofire.request(.POST, "http://...
96
votes
21
answers
55k
views
Cocoapods + Cannot load underlying module for 'x'
I am running XCode 7, Swift 2.0, iOS 9.
I want to install Alamofire in my project using Cocoapods. I have done the following:
gem install cocoapods
pod setup
pod init
Updated Podfile to:
# ...
90
votes
6
answers
47k
views
Module 'Alamofire' has no member named 'request'
I'm new to iOS Development, I installed Alamofire as said in README, but I have this error as other users and I don't know how to solve it.
90
votes
13
answers
46k
views
IPv6 App Store Rejection
Our update has been rejected twice today for ipv6 network connectivity issues. Our networking code has not changed between the previous release and this current release.
The app only makes https ...
88
votes
10
answers
77k
views
JSONSerialization Invalid type in JSON write (_SwiftValue)
Why does the following code give me the error:
Invalid type in JSON write (_SwiftValue).
The error is thrown on this line:
urlRequest.httpBody = try JSONSerialization.data(withJSONObject: ...
80
votes
3
answers
39k
views
AlamoFire asynchronous completionHandler for JSON request
Having used the AlamoFire framework I've noticed that the completionHandler is run on the main thread. I'm wondering if the code below is a good practice for creating a Core Data import task within ...
78
votes
10
answers
50k
views
How can I log each request/response using Alamofire?
Is there a way to log each request / response using Alamofire (something similar to AFNetworkActivityLogger) ?
I am aware of Printable, DebugPrintable and Output (cURL) but they are not quite what I ...
78
votes
6
answers
36k
views
Proper usage of the Alamofire's URLRequestConvertible
I've read couple tutorials, README from @mattt but can't figure out couple things.
What is the proper usage of URLRequestConvertible in real world API? It looks like if I will create one router by ...
77
votes
27
answers
53k
views
Failed to load Info.plist from bundle
Cannot run app. Failed to load Info.plist from bundle error occurs.
When I CMD+K clean the project, it runs fine. But I have to clean the project every time I make changes and run the app.
Following ...
76
votes
14
answers
137k
views
Send POST parameters with MultipartFormData using Alamofire, in iOS Swift
I am using Alamofire, very first time. I am using the latest version Alamofire 1.3.1. I want to send one image , one video and some POST parameters in one API call. I am using multipart form data. The ...
76
votes
11
answers
78k
views
'Method' is ambiguous for type lookup in this context, Error in Alamofire
I am using Alamofire for network handling in swift and run into one weird error. It seems like we can't pass Method enum as parameter. [Error is on Method parameter]
private func apiRequest(method: ...
73
votes
1
answer
20k
views
NSURLSession concurrent requests with Alamofire
I'm experiencing some strange behaviour with my test app. I've about 50 simultaneous GET requests that I send to the same server. The server is an embedded server on a small piece of hardware with ...
71
votes
11
answers
101k
views
how to use Alamofire with custom headers
I am just starting to take a look at Mattt's wonderful new Alamofire swift networking library and am not quite sure how one would use it with custom headers.
The code i am trying to convert from ...
68
votes
9
answers
65k
views
Sending json array via Alamofire
I wonder if it's possible to directly send an array (not wrapped in a dictionary) in a POST request. Apparently the parameters parameter should get a map of: [String: AnyObject]?
But I want to be able ...
67
votes
16
answers
77k
views
Set timeout in Alamofire
I am using Alamofire 4.0.1 and I want to set a timeout for my request. I tried the solutions gived in this question:
In the first case, it throws a NSURLErrorDomain (timeout is set correctly):
let ...
63
votes
5
answers
42k
views
How to return value from Alamofire
I am making url calls thru an API that I created using swift as follows:
class API {
let apiEndPoint = "endpoint"
let apiUrl:String!
let consumerKey:String!
let consumerSecret:String!
var ...
62
votes
3
answers
44k
views
What are Embedded Binaries in Xcode?
I'm using Alamofire in a Swift project, and part of their manual installation instructions are to add Alamofire under Embedded Binaries in the General tab for my application target.
What are Embedded ...
62
votes
3
answers
24k
views
Synchronizing remote JSON data to local cache storage in iOS Swift
I am trying to find the solution for simple processing all necessary steps for read-only consuming remote JSON data on iOS devices. It means fetching remote JSON data, store to local cache on iOS ...
57
votes
2
answers
37k
views
Any way to get the response body during HTTP errors?
I'm hitting an API that will occasionally throw a HTTP 403 error, and the response body can give some extra information in the form of json, however for the life of me I can't seem to get the ...
55
votes
9
answers
44k
views
How to disable caching in Alamofire
When I send a GET request twice with Alamofire I get the same response but I'm expecting a different one. I was wondering if it was because of the cache, and if so I'd like to know how to disable it.
54
votes
15
answers
29k
views
Extra argument 'method' in call
Getting error while calling Alamofire request method in the latest version(4.0.0).
The syntax is:
Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: .JSON, headers: [:]...
54
votes
14
answers
73k
views
Alamofire Swift 3.0 Extra argument in call
I have migrated my project to Swift 3 (and updated Alamofire to latest Swift 3 version with pod 'Alamofire', '~> 4.0' in the Podfile).
I now get an "Extra argument in call" error on every ...
54
votes
7
answers
41k
views
Chain multiple Alamofire requests
I'm looking for a good pattern with which I can chain multiple HTTP requests. I want to use Swift, and preferrably Alamofire.
Say, for example, I want to do the following:
Make a PUT request
Make a ...
52
votes
5
answers
25k
views
Swift Alamofire VS AFNetworking
I am developing an app using Swift. I want to call a REST API. I found there are two popular libraries, AFNetworking and Alamofire. But I don't know which is better (is more popular or has more ...
48
votes
11
answers
62k
views
Handle timeout with Alamofire
Is it possible to add timeout handler for Alamofire request?
In my project I use Alamofire this way:
init() {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
...
46
votes
2
answers
60k
views
How to add Alamofire URL parameters
I have a working scenario using Postman passing in URL parameters. Now when I try to do it via Alamofire in Swift, it does not work.
How would you create this url in Alamofire?
http://localhost:8080/?...
46
votes
12
answers
89k
views
upload image to server using Alamofire
this is my code that I want to upload image to server using Alamofire, it not error but it can't push image to server. what should I do?
let url = URL(string: urlString)!
var urlRequest = URLRequest(...
46
votes
4
answers
30k
views
Swift 3 Alamofire multipart upload
Thanks to migration to Swift 3, I find it difficult to compile my project that uses Alamofire.
The problem occurs when uploading multipartFormData:
Alamofire.upload(.POST, URL, headers: headers, ...
46
votes
2
answers
33k
views
SSL_ERROR_SSL(1): operation failed within the library
I am getting some SSL Errors (which are causing my project to stop/hang with no crash as I have a DispatchGroup waiting for the request), which I don't know how they are caused, what they are, or what ...
45
votes
3
answers
31k
views
AlamoFire Download in Background Session
I am using Alamofire within a new app (A Download Manager Sample based on Alamofire)
I need some clarifications about downloading files using the background session.
I need to override SessionDelegate ...
44
votes
11
answers
56k
views
Cannot install Alamofire in new Xcode Project. "No Such module Alamofire"
I follow the instructions to the T. Fresh install of all, yet getting the error:
"No Such module Alamofire"
Directions here:
In the meantime, you can simply add Alamofire as a git submodule, drag ...
41
votes
9
answers
46k
views
How to check internet connection in alamofire?
I am using below code for making HTTP request in server.Now I want to know whether it is connected to internet or not. Below is my code
let request = Alamofire.request(completeURL(domainName: path)...
41
votes
6
answers
24k
views
AlamoFire does not respect timeout interval
class APIClient {
var user = User()
let alamoFireManager : Alamofire.Manager?
let center = NSNotificationCenter.defaultCenter()
init(){
let configuration = ...
40
votes
10
answers
95k
views
How to load image in swift using Alamofire
I have a collection view controller, which load image Async by URL.
(Something like Instegram)
I am looking for the best way to implement the part of the loading image.
please tell me what do you ...
40
votes
9
answers
41k
views
How to convert a Swift object to a dictionary
I'm relatively new to iOS programming. However, I would have assumed that Swift would have an automated way of converting objects to JSON and vice versa. That being said, I have found several ...
40
votes
3
answers
10k
views
Swift variable name with ` (backtick)
I was browsing Alamofire sources and found a variable name that is backtick escaped in this source file
open static let `default`: SessionManager = {
let configuration = URLSessionConfiguration....
39
votes
2
answers
11k
views
Does Alamofire store the cookies automatically?
I'm new to Alamofire so I'm sorry if this it's a noob question: this framework stores the cookies automatically?
This is because I have a simple request like this:
Alamofire.request(.POST, loginURL, ...
38
votes
7
answers
65k
views
Download File Using Alamofire 4.0 (Swift 3)
In older version of Alamofire. This is how I download file
let destinationPath = Alamofire.Request.suggestedDownloadDestination( directory: .documentDirectory, domain: .userDomainMask);
...
38
votes
2
answers
18k
views
Alamofire : How to handle errors globally
My question is quite similar to this one, but for Alamofire : AFNetworking: Handle error globally and repeat request
How to be able to catch globally an error (typically a 401) and handle it before ...
37
votes
20
answers
61k
views
Alamofire No Such Module (CocoaPods)
Using Xcode 7
I am trying to install Alamofire in a sample project. Have used the instructions from Ray Wenderlich's page
Only change from above link is the podfile -- which is from GitHub page here ...
34
votes
4
answers
39k
views
Alamofire returns .Success on error HTTP status codes
I have a pretty simple scenario that I'm struggling with. I'm using Alamofire to register a user on a rest API. The first call to register is successful and the user can log in. The second call, when ...
34
votes
6
answers
27k
views
Cancel a request Alamofire
I am sending a request which is triggered based on timer. But if I press the back button the request still seems to be active and the response in turns crashes the app. Kindly suggest a way to cancel ...
34
votes
4
answers
17k
views
Unit Testing HTTP traffic in Alamofire app
I'm struggling a bit to figure out how to best test an app that uses Alamofire to help sync with server data.
I want to be able to test my code that uses Alamofire and processes JSON responses from a ...
33
votes
11
answers
44k
views
How to use NetworkReachabilityManager in Alamofire
I want functionality similar to AFNetworking in Objective-C with Alamofire NetworkReachabilityManager in Swift:
//Reachability detection
[[AFNetworkReachabilityManager sharedManager] startMonitoring];...