alamofire

Handle JSON Response with Alamofire in Swift

天大地大妈咪最大 提交于 2019-12-17 16:55:10
问题 sorry for my bad english :) I have a problem to parse JSON response over Alamofire in Swift for an iOS app. I wrote a function to return a string of JSON response. The request and response handling I do with Alamofire and the JSON handling I do with SwiftyJSON. At the begin I declare a var called jsonString with the value test . Then I do a request to an REST Service and get a JSON response by clicking a button. This response I want to return with the function ping(url:String) . At the end I

iOS Alamofire stop all requests

元气小坏坏 提交于 2019-12-17 15:44:24
问题 Is there any way I can for example say: Alamofire.Manager.cancelAllRequests() or Alamofire.Manager.sharedInstance.cancelAllRequests() ? Of course it would be great if these requests especially in case of image download would only be paused for later when I'll cal the same URL but... I need at least to be able to cancel all requests at a global level. Some suggestions ? In my app I have a wrapper above the Alamofire.request(.Post....) way of doing things so I would really appreciate not making

Set timeout in Alamofire

本小妞迷上赌 提交于 2019-12-17 15:32:35
问题 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

Alamofire with -d

冷暖自知 提交于 2019-12-17 15:00:16
问题 I need to make request like this Postman one, but in Alamofire curl -X DELETE \ http://someUrl \ -H 'authorization: JWT someToken' \ -H 'cache-control: no-cache' \ -H 'content-type: application/x-www-form-urlencoded' \ -H 'postman-token: 0149ef1e-5d45-34ce-3344-4b658f01bd64' \ -d id=someId I guess it should be something like: let headers = ["Content-Type": "application/x-www-form-urlencoded", "Authorization": "JWT someToken"] let params: [String: Any] = ["id": "someId"] Alamofire.request(

Swift and using class extension

给你一囗甜甜゛ 提交于 2019-12-17 12:44:09
问题 I don't understand why programmers use the extension keyword in their class implementation. You can read in other topics that code is then more semantically separated and etc. But when I work with my own code, it feels clearer to me to use // MARK - Something . Then when you use methods list (ctrl+6) in Xcode, everything is seen at first look. In Apple documentation you can read: “Extensions add new functionality to an existing class, structure, or enumeration type.” So why not write my own

AlamoFire asynchronous completionHandler for JSON request

倖福魔咒の 提交于 2019-12-17 08:04:37
问题 Having used the AlamoFire framework I've noticed that the completionHandler is run on the main thread. Im wondering if the code below is a good practice for creating a Core Data import task within the completion handler: Alamofire.request(.GET, "http://myWebSite.com", parameters: parameters) .responseJSON(options: .MutableContainers) { (_, _, JSON, error) -> Void in dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in if let err = error{ println("Error:\

AlamoFire asynchronous completionHandler for JSON request

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 08:03:22
问题 Having used the AlamoFire framework I've noticed that the completionHandler is run on the main thread. Im wondering if the code below is a good practice for creating a Core Data import task within the completion handler: Alamofire.request(.GET, "http://myWebSite.com", parameters: parameters) .responseJSON(options: .MutableContainers) { (_, _, JSON, error) -> Void in dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in if let err = error{ println("Error:\

Alamofire fire variable type has no subscript members

我是研究僧i 提交于 2019-12-17 07:50:19
问题 After updating to Alamofire 4 and updating my code to Swift 3, all of my requests are not working for some reason. The variables that I am trying to utilize are highlighted in red and say "Type Any' has no subscript members" Here is my code: Alamofire.request("https://example.com/notifications.php?action=\(action)&UUID=\(UniversalUUID)&token=\(token)").responseJSON{ (response) -> Void in if let JSON = response.result.value{ let message = JSON["message"] as! String print(message) } 回答1: You

Checking for multiple asynchronous responses from Alamofire and Swift

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 06:36:14
问题 I am writing an application that depends on data from various sites/service, and involves performing calculations based on data from these different sources to produce an end product. I have written an example class with two functions below that gathers data from the two sources. I have chosen to make the functions different, because sometimes we apply different authentication methods depending on the source, but in this example I have just stripped them down to their simplest form. Both of

Send POST parameters with MultipartFormData using Alamofire, in iOS Swift

穿精又带淫゛_ 提交于 2019-12-17 03:24:14
问题 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 mutipart module is working. I am facing a problem to send extra POST parameters params . Below is my code. "params" is the dictionary which contains extra parameters? How can I append these POST parameters in the request. Please help var fullUrl :String = Constants.BASE_URL + "/api