alamofire

Alamofire network calls not being run in background thread

青春壹個敷衍的年華 提交于 2019-12-17 22:19:52
问题 It is my understanding that by default, Alamofire requests run in a background thread. When I tried running this code: let productsEndPoint: String = "http://api.test.com/Products?username=testuser" Alamofire.request(productsEndPoint, method: .get) .responseJSON { response in // check for errors guard response.result.error == nil else { // got an error in getting the data, need to handle it print("Inside error guard") print(response.result.error!) return } // make sure we got some JSON since

How to use Alamofire with custom headers for POST request

痞子三分冷 提交于 2019-12-17 22:14:56
问题 I implemented a POST request with Alamofire with a custom header, because we work with OAuth2 and we have to send an access token in every request inside the header. In this case I have to use a custom header. The access token value for the HTTP header field Authorization does not work for me. The server generates an error because the header information for OAuth with the access token is not available. But what is the mistake in my code? Here is my current code: let URL = NSURL(string: url +

Unit Testing HTTP traffic in Alamofire app

蓝咒 提交于 2019-12-17 21:46:53
问题 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 server. I'd like to mock those tests so that I can feed the expected response data to those tests without incurring real network traffic. This blog post (http://nshipster.com/xctestcase/) describes how easy it is to Mock an object in Swift - but I'm not sure how to do that with Alamofire and its

How to call post service with parameters swift 3.0 Alamofire 4.0?

大憨熊 提交于 2019-12-17 21:25:38
问题 I have parameters in var Param : [String:String] = [:] I am using Alamofire.upload( multipartFormData: { multipartFormData in but in response it says invalid service is their in parameter encoding it goes wrong ? 回答1: multipartFormData is used to upload images on server. So if you want to upload image data then try to use below code. let payload: [String: AnyObject] = [ "key1": "val1" as AnyObject, "key2": true as AnyObject, "key3" : [1,2,3,4] as AnyObject ] let requestString = "http://www

How to upload zip data with alamofire?

本秂侑毒 提交于 2019-12-17 21:22:00
问题 I try to upload data using Alamofire Issue is: if I try to upload image from project it works ok, but if I try to upload zip dir I got error and timeout exception There is my code which produces timeout exception let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = 10 // seconds configuration.timeoutIntervalForResource = 10 alamoFireManager = Alamofire.SessionManager(configuration: configuration) let fileData = FileManager.default.contents(atPath:

Cannot add Alamofire to Swift Project

时光毁灭记忆、已成空白 提交于 2019-12-17 19:56:30
问题 Trying to add alamofire to swift project using unstruction from here Did all these steps, clean project a lot of timer and restarted XCode, nothing helps. Error does not dissappear http://i.stack.imgur.com/kNU3R.png "Cannot load underlying module for 'Alamofire'" and nothing to do Changes I did: 1) added project file to my project i.stack.imgur.com/eUe8E.png 2) added to build phases panel i.stack.imgur.com/1wanl.png 3) added to general tab i.stack.imgur.com/L3TTR.png What`s wrong with that?

Alamofire - NSURLCache is not working?

对着背影说爱祢 提交于 2019-12-17 17:58:40
问题 I set my cache as below var cacheSizeMemory = 20 * 1024 * 1024 var cacheSizeDisk = 100 * 1024 * 1024 var sharedCache = NSURLCache(memoryCapacity: cacheSizeMemory, diskCapacity: cacheSizeDisk, diskPath: "SOME_PATH") NSURLCache.setSharedURLCache(sharedCache) Create request with cache policy var request = NSMutableURLRequest(URL: NSURL(string: "\(baseUrl!)\(path)")!, cachePolicy: .ReturnCacheDataElseLoad, timeoutInterval: timeout) Make a request and get a response with following Cache-Control

How to connect to self signed servers using Alamofire 1.3

删除回忆录丶 提交于 2019-12-17 17:56:09
问题 I get the below error while connecting to self signed server. Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “maskeddomain.com” which could put your confidential information at risk." UserInfo=0x7fb6dec259e0 {NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9813, NSUnderlyingError=0x7fb6dbe0dd90 "The

Alamofire : How to handle errors globally

て烟熏妆下的殇ゞ 提交于 2019-12-17 17:20:03
问题 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 other requests are made (and eventually failed if not managed) ? I was thinking of chaining a custom response handler, but that's silly to do it on each request of the app. Maybe subclassing, but which class should i subclass to handle that ? 回答1: Handling refresh for 401 responses in an oauth flow

How to send multiple JSON objects as a stream using alamofire

我怕爱的太早我们不能终老 提交于 2019-12-17 17:15:10
问题 I want to send multiple different JSON object in a single request, i felt streaming the multiple JSON objects like a file in a single request would be better, so kindly let me know if it is possible, if so kindly give me an idea of how to do it using Alamofire, Below is the formate of the raw body (application/json) data that i want to post {"a":23214,"b":54674,"c":"aa12234","d":4634} {"a":32214,"b":324674,"c":"as344234","d":23434} {"a":567214,"b":89674,"c":"sdf54234","d"34634} I tried the