alamofire

Using Alamofire in UI Test Target

蹲街弑〆低调 提交于 2020-01-02 09:28:15
问题 The below code snippet using Alamofire works fine in iOS app but the code does not work in iOS UI Testing target. let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.HTTPAdditionalHeaders = Alamofire.Manager.defaultHTTPHeaders manager = Alamofire.Manager(configuration: configuration) manager!.request(.GET, "https://www.google.com") .responseString { response in print(response.request) // original URL request print(response.response) // URL response print

Alamofire with google geocoding api

痴心易碎 提交于 2020-01-02 09:10:51
问题 In one of my apps I need to geocode address string. At first I considered using CLGeocoder . However, after I tried it I stumbled upon a problem which I described in this question. The solution was to use Google's Geocoding APIs instead. I have now switched to them and managed to get them working by having the following functions: func startConnection(){ self.data = NSMutableData() let urlString = "https://maps.googleapis.com/maps/api/geocode/json?address=\(searchBar.text!)&key=MYKEY" let

Alamofire 4, Swift 3 and building a json body

对着背影说爱祢 提交于 2020-01-02 04:11:29
问题 {"title":"exampleTitle","hashTags":[{"name":"tag1"},{"name":"tag2"}],"uploadFiles": [{"fileBytes":"seriesOfBytes\n","filename":"upload.txt"}]} That is my desired body I want to send to the backend. I'm using Swift 3.0 and Alamofire 4 and i have multiple questions. first , How do i correctly create a body which contains values and arrays of values? My approach is: let para:NSMutableDictionary = NSMutableDictionary() para.setValue("exampleTitle", forKey: "title") let jsonData = try!

Wait for asynchronous request result

≯℡__Kan透↙ 提交于 2020-01-02 02:54:17
问题 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

Swift 4 AlamofireImage with UITableView Cell

这一生的挚爱 提交于 2020-01-02 01:15:28
问题 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)

Having issue uploading image using Alamofire and Swift 4

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 12:11:11
问题 I am trying to upload image from gallery to server via my app. Here is my code : func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { if let userID:String = userDefaults.string(forKey: "userID"){ let URL: String = "HERE_IS_URL" let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage let imageData = UIImageJPEGRepresentation(chosenImage, 1.0) dismiss(animated: true, completion: nil) userProfilePicture.image =

Having issue uploading image using Alamofire and Swift 4

荒凉一梦 提交于 2020-01-01 12:11:10
问题 I am trying to upload image from gallery to server via my app. Here is my code : func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { if let userID:String = userDefaults.string(forKey: "userID"){ let URL: String = "HERE_IS_URL" let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage let imageData = UIImageJPEGRepresentation(chosenImage, 1.0) dismiss(animated: true, completion: nil) userProfilePicture.image =

How to pass dictionary as a parameter in the method in Swift?

杀马特。学长 韩版系。学妹 提交于 2020-01-01 09:36:09
问题 I have created following method in my code: func SignIn(objDictionary:Dictionary<String,String>) { //Body of method } I need to pass the following dictionary as a parameter in this method which is defined below: let objSignInDictionary:Dictionary = ["email":emailTextField.text, "password":passwordTextField.text] How can I pass this dictionary in the above method as a parameter? This should be noted that method is in another class and I am calling the method by creating its object as follows:

Code=-1001 “The request timed out.”

假装没事ソ 提交于 2020-01-01 09:15:16
问题 I am working on a Swift project which requires a lot of consumption of APIs. Everything is working fine but sometimes (1 in 20), I get Code=-1001 "The request timed out." error while calling the API. I am using Alamofire. I am attaching the code to call API. let request = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" request.HTTPBody = myUrlContents.dataUsingEncoding(NSUTF8StringEncoding) request.timeoutInterval = 15 request.setValue("application/x-www-form-urlencoded",

AlamofireImage af_setImageWithURL in a UITableViewCell without placeholder image

狂风中的少年 提交于 2020-01-01 08:43:28
问题 I'm using AlamofireImage to set an image on a UIImageView in a UITableViewCell like so: cell.imageView.af_setImageWithURL(url) The image doesn't show after downloading. It will show the image the second time when it's loaded from the memory cache. It seems that using a placeholder image makes all the difference. This works and prints the address of the (downloaded) image: cell.imageView.af_setImageWithURL(URL, placeholderImage: UIImage(named: "placeholder"), filter: nil, imageTransition: