alamofire

Background request not execute Alamofire Swift

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 09:23:52
I'm trying to make calls in background like POST,GET to be more precise in the didReceiveRemoteNotification method, because they start to work as a push notification arrive. My problem is that all the Alamofire.request are never call in Background mode until I open the app. I have by now Im was trying to open a session but it won't make the request work. These is what i want to execute in background (cellphone in background) Alamofire.Manager(configuration: configuration).request(.GET, url, parameters: nil) .responseJSON { (_, _, JSON, _) in //println(JSON) println(JSON) REST OF THE CODE But

How to clear AlamofireImage setImageWithURL cache

被刻印的时光 ゝ 提交于 2019-11-28 08:36:54
I am using AlamofireImage in my project quite a lot and I use let URL = NSURL(string: "https://cdn.domain.com/profile/image.jpg")! imageView.af_setImageWithURL(URL) to fetch an image from my CDN. I have done some tests but correct me if I am wrong, this seems to store the downloaded image in to a cache. My tests included downloading a 5mb image. The first time it took about 20 seconds, the second time was instant. The thing I would like to know is how can I clear the cache for a specific URL/image and re-download the image? Say for example I update a users profile pic. The image name/URL will

Progress of a Alamofire request

我的梦境 提交于 2019-11-28 07:45:27
问题 Will it be possible to show progress for Alamofire.request(.POST, URL, parameters: parameter, encoding: .JSON) .responseJSON { response in // Do your stuff } I get my images/documents as a base64 string then I convert it as files in mobile Can I show a progress bar with percentage? I am using Alamofire, Swift 2 回答1: The way you monitor progress in Alamofire is using the progress closure on a Request . More details on usage can be found in the README. While that example in the README

'Method' is ambiguous for type lookup in this context, Error in Alamofire

為{幸葍}努か 提交于 2019-11-28 06:56:50
问题 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: Method, url: String, apiData: [String : AnyObject], completion:(finished: Bool, response: AnyObject?) ->Void) { Alamofire.request(method, url, parameters: apiData).responseJSON{ response in if let JSON = response.result.value { completion(finished: true, response: JSON) } else { completion(finished

Setting snippet data for youtube upload via REST API using Swift

给你一囗甜甜゛ 提交于 2019-11-28 06:52:26
问题 I'm able to successfully upload a video to youtube via their REST API using the following code: func postVideoToYouTube(token: String, callback: Bool -> Void){ let headers = ["Authorization": "Bearer \(token)"] let path = NSBundle.mainBundle().pathForResource("video", ofType: "mp4") let videodata: NSData = NSData.dataWithContentsOfMappedFile(path!)! as! NSData upload( .POST, "https://www.googleapis.com/upload/youtube/v3/videos?part=id", headers: headers, multipartFormData: { multipartFormData

How to get the result value of Alamofire.request().responseJSON in swift 2?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 06:17:06
I have a question about the new version of Alamofire for Swift 2 Alamofire.request(.POST, urlString, parameters: parameters as? [String : AnyObject]) .responseJSON { (request, response, result) -> Void in let dico = result as? NSDictionary for (index, value) in dico! { print("index : \(index) value : \(value)") } } In this section I would like to cast the result in to a NSDictionary. But When I compile and put a breakpoint, the debugger says that dico is nil. If I use debugDescription to print result, it is not nil and contains what I expected How can I cast the Result variable? The accepted

Alamofire - NSURLCache is not working?

岁酱吖の 提交于 2019-11-28 06:06:05
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 private, max-age=60 Then try to check the cache var cachedResponse = NSURLCache.sharedURLCache()

Setting Alamofire custom destination file name instead of using suggestedDownloadDestination in Swift 3.0

主宰稳场 提交于 2019-11-28 05:56:18
问题 How to write the following snippet in swift 3.0 ? The following syntax is in swift 2 Alamofire.download(.POST, invoice.url,parameters:params, destination: { (url, response) -> NSURL in let pathComponent = response.suggestedFilename let fileManager = NSFileManager.defaultManager() let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] let fileUrl = directoryURL.URLByAppendingPathComponent(pathComponent) return fileUrl }) .progress { bytesRead,

How to upload image with parameters using Alamofire in Swift

好久不见. 提交于 2019-11-28 05:55:36
I am developing an iPhone application with swift. and I'am using Alamofire framework for handling http requests. I use Alamofire.request for POST , GET and etc like this: Alamofire.request(.POST, myURL , parameters: ["a": "1", "b" : "2" ]) .response { (request, response, data, error) in } And I use Alamofire.upload to upload image to server this : Alamofire.upload(.POST, uploadURL , fileURL) And both works perfectly, but now I want to upload an image and also send some parameters with, and my content type should be multipart/form-data and Alamofire.upload does not accept parameters. There are

Set timeout in Alamofire

安稳与你 提交于 2019-11-28 04:55:19
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 configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = 10 let sessionManager = Alamofire.SessionManager(configuration: configuration) sessionManager.request("yourUrl", method: .post, parameters: ["parameterKey": "value"]) .responseJSON { response in switch (response.result) { case .success: //do json stuff break case .failure(let error): if error._code ==