alamofire

How to upload multiple images in multipart using Alamofire?

家住魔仙堡 提交于 2019-11-27 07:50:11
问题 I am stuck in uploading multiple images in multipart using Alamofire. Can any one help me? Thanks in advance!! For more details, I am using this code to create body part of images data: func imageArrayToNSData(array: [UIImage],boundary:String) -> NSData { let body = NSMutableData() var i = 0; for image in array{ let filename = "image\(i).jpg" let data = UIImageJPEGRepresentation(image,0.8); let mimetype = "image/jpeg" let key = "product_images" body.appendData("--\(boundary)\r\n"

What is the reason behind not importing Alamofire in my project?

孤街醉人 提交于 2019-11-27 07:33:22
问题 I am making a demo of Alamofire using cocoa-pods.I am referring the tutorial "https://github.com/Alamofire/Alamofire". I tried both manual and by sample procedure .But, when i am importing Alamofire,an error shows like "No such module 'Alamofire' ". So please help me to short out this issue. Thanks in advance. 回答1: Follow these steps for installation > 1- open terminal and cd to your project folder 2- Create Podfile and add the code from https://github.com/Alamofire/Alamofire 3- In terminal ,

Checking for multiple asynchronous responses from Alamofire and Swift

一世执手 提交于 2019-11-27 07:08:34
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 the functions use Alamofire to fire off and handle the requests. I then have an initialisation function,

How to check internet connection in alamofire?

泄露秘密 提交于 2019-11-27 06:55:23
I am using below code for making HTTP request in server.Now I want to know whether it is connected to internet or not. Below is my code let request = Alamofire.request(completeURL(domainName: path), method: method, parameters: parameters, encoding: encoding.value, headers: headers) .responseJSON { let resstr = NSString(data: $0.data!, encoding: String.Encoding.utf8.rawValue) print("error is \(resstr)") if $0.result.isFailure { self.failure("Network") print("API FAILED 4") return } guard let result = $0.result.value else { self.unKnownError() self.failure("") print("API FAILED 3") return } self

how to make alamofire download progress run in background ios?

妖精的绣舞 提交于 2019-11-27 06:33:18
问题 I am using Alamofire to download data How to make alamofire run download in background with swift? Thanks 回答1: The basic idea is as follows: The key problem is that with background downloads, your app may actually be terminated while downloads are in progress (e.g. jettisoned due to memory pressure). Fortunately, your app is fired up again when background downloads are done, but any task-level closures you originally supplied are long gone. To get around this, when using background sessions,

AlamoFire asynchronous completionHandler for JSON request

跟風遠走 提交于 2019-11-27 05:53:18
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:\(error)") return; } if let jsonArray = JSON as? [NSArray]{ let importer = CDImporter(incomingArray:

Parsing JSON using the new Swift 3 and Alamofire

梦想的初衷 提交于 2019-11-27 05:52:11
问题 I'm using Alamofire as HTTP library, since the update to Swift 3, how do you parse JSON based on the example below? Alamofire.request("https://httpbin.org/get").responseJSON { response in debugPrint(response) if let json = response.result.value { print("JSON: \(json)") } } respone.result.value is of Any object, and is very new and confusing. 回答1: As you can see in Alamofire tests you should cast response.result.value to [String:Any] : if let json = response.result.value as? [String: Any] { //

Downloading UIImage via AlamofireImage? [duplicate]

不问归期 提交于 2019-11-27 05:33:18
This question already has an answer here: How can I get the Data from NSURLSession.sharedSession().dataTaskWithRequest 2 answers I have a URL and want to download the image via a return function, however I cant get it to cooperate properly, here is my func: func getTabImage(url: URL) -> UIImage { Alamofire.request(url) .responseImage { response in if let image = response.result.value { return image } else { print("Failed to get image") } } } I pass in the URL, and want a UIImage returned from the alamofire response. But i get Unexpected non-void return value in void function for the return

Alamofire fire variable type has no subscript members

我是研究僧i 提交于 2019-11-27 05:30:51
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) } You need to add as? [String: Any] Alamofire.request(yourURL).responseJSON { (response) in switch response.result {

Upload multiple images in swift using Alamofire

社会主义新天地 提交于 2019-11-27 05:22:59
问题 I'm using the following code to upload a single image to a server: private static func urlRequestWithComponents(urlString:String, parameters:Dictionary<String, String>, imageData:NSData?, imageName: String) -> (URLRequestConvertible , NSData) { // create url request to send let mutableURLRequest = NSMutableURLRequest(URL: NSURL(string: urlString)!) mutableURLRequest.HTTPMethod = Alamofire.Method.POST.rawValue let boundaryConstant = "myRandomBoundary12345"; let contentType = "multipart/form