alamofire

Could not cast value of type '__NSArrayI' (0x10df73c08) to 'NSDictionary' (0x10df74108)

ε祈祈猫儿з 提交于 2019-12-05 06:19:30
let url = "http://xyz/index_main.php?c=webservices&a=get&e=007" Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default) .responseJSON { response in print(response) //to get status code if let status = response.response?.statusCode { switch(status){ case 201: print("example success") default: print("error with response status: \(status)") } } //to get JSON return value if let result = response.result.value { let JSON = result as! NSDictionary print(JSON) } Result : { "create_by" = 007; "create_date" = "2016/06/20"; "due_date" = "2016/06/22"; "estimate_time" = "";

“Cannot call value of non-function type 'HTTPURLResponse?'” (Alamofire 4.0) [Swift 3.0]

*爱你&永不变心* 提交于 2019-12-05 06:09:12
I'm receiving this error: "Cannot call value of non-function type 'HTTPURLResponse?'" on the section: .response { (request, response, data, error) and I was wondering if anyone can help me with this. Alamofire.download(urlToCall, method: .get) { temporaryURL, response in if FileManager.default.fileExists(atPath: finalPath!.path!) { do { try FileManager.default.removeItem(atPath: finalPath!.path!) } catch { // Error - handle if required } } return finalPath! } .response { (request, response, data, error) in if error != nil { } var myDict: NSDictionary? let path = finalPath! myDict =

Alamofire Image: Fetch Image from AutoPurgingImageCache after af_setImageWithURL()

孤街醉人 提交于 2019-12-05 05:02:27
问题 I use AlamofireImage in my project. I use someImageView.af_setImageWithURL(url) a lot. However at some point I need to fetch an image manually from the imageCache, because I do not want to apply it to an UIImageView. This brings up 2 problems: I can access the image cache directly by creating one with let imageCache = AutoPurgingImageCache() . Is this the same cache as .af_setImageWithURL() uses (Singleton)? Or is this a new one? Which is worthless in my case, because I could not profit from

Wait for asynchronous request result

筅森魡賤 提交于 2019-12-05 04:49:00
I would like somehow to asynchronously validate the pin in ABPadLockScreen since pins are not saved on the device. I'm using Alamofire for http requests along with PromiseKit to have promises. I have tried to use AwaitKit but the problem is that i get into a deadlock. I have also tried to use semaphore as well, but the result is the same. Since i can't change the ABPadLock method to accommodate something like a completion handler i need some solution, it doesn't matter if it blocks the main thread, just that it works. Alamofire request method: public func loginAsync(pinCode: String?, apiPath:

Prevent redirect response with Alamofire in Swift

最后都变了- 提交于 2019-12-05 04:43:07
问题 I'm looking for example code how to prevent redirect response (status code 3xx) when request web api. I'm using Swift with Alamofire 1.2. I have tried: delegate.taskWillPerformHTTPRedirection = { (session: NSURLSession!, task: NSURLSessionTask!, response: NSHTTPURLResponse!, request: NSURLRequest!) in return nil } but not work I've also tried: https://github.com/Alamofire/Alamofire/pull/350/files and have changed my own code to: var acc = self.txtAccount.text var pwd = self.txtPassword.text

Multiple encoding types for Alamofire Request

筅森魡賤 提交于 2019-12-05 03:59:45
I need to make a POST request with an HTTP Body with a JSON object, but I also need to use url query parameters in the same request. POST: http://www.example.com/api/create?param1=value&param2=value HTTP Body: { foo : [ bar, foo], bar: foo} Is this supported by Alamofire? How would I go about doing this? This is definitely a valid use case. I've ran into similar issues with trying to append access tokens as query parameters to a POST request. Here's a function that should make things a bit easier for the time being that is similar to your approach. func multiEncodedURLRequest( method:

cURL with Alamofire - Swift - multipart/form-data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:25:48
问题 First, im sorry if this question is stupid but im pretty new to this stuff. I've tried different things to create the swift equivalent of this cURL request with Alamofire, but I don't know how to send the image as a multipart/form-data to the API. curl -X POST -F "file=@/Users/nicolas/sample.png" -F "mode=document_photo" https://api.idolondemand.com/1/api/sync/ocrdocument/v1 -F "apikey=xxx-xxx-xxx-xxx-xxx" I think current code is pretty wrong for this type of request, but still i'm gonna post

Alamofire: [Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-999 “cancelled”

懵懂的女人 提交于 2019-12-05 02:19:32
The service I'm connecting to is using a self signed certificate. For dev purposes I do not want to validate that chain. Using swift 3 with Alamofire 4. Fixed the ATS accordingly: <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>url.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict> Code to connect and disable evaluation. let serverTrustPolicies: [String: ServerTrustPolicy] = [ "example.domain.com": .pinCertificates(

Do I need to wrap my Alamofire calls inside dispatch_async?

放肆的年华 提交于 2019-12-05 02:00:57
func authenticate(completion:(success: Bool) -> Void) { let qos = Int(QOS_CLASS_USER_INITIATED.value) dispatch_async(dispatch_get_global_queue(qos, 0)){ () -> Void in Alamofire.request(.POST, CONSTANTS.Domain+"/accounts", parameters: ["" : ""]).responseJSON { (req, res, json, error) in dispatch_async(dispatch_get_main_queue()){ completion(success: true) } } } } Or, can I leave out the dispatch and just keep my code simple? Schemetrical Alamofire is designed to be asynchronous. On another note, if the method has as callback, most likely it is asynchronous. So, yes you can leave out the dispatch

Swift 4 AlamofireImage with UITableView Cell

别等时光非礼了梦想. 提交于 2019-12-05 01:37:39
I am using AlamofireImages to try to download an image from a server and display it in my table view cell, this is what I got, but my images does not appear, just the textLabel and detailTextLabel override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "trendingCell", for: indexPath) print(self.array[indexPath.row]) cell.textLabel?.text = (self.array[indexPath.row]["title"] as! String) cell.detailTextLabel?.text = (self.array[indexPath.row]["username"] as! String) Alamofire.request("http: