alamofire

Swift 4 Alamofire multipart upload not working

元气小坏坏 提交于 2019-12-04 05:24:55
问题 I am using alamofire 4.7 and swift 4 I need to upload image and json to server. I am using the following code below for uploading bu I am getting result failure but data is inserting in server but not getting response, showing some serialization error as something like this ▿ result : FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo=

Parsing JSON data from alamofire into Array with Dictionary

和自甴很熟 提交于 2019-12-04 04:48:12
问题 I'm trying to parse JSON data from alamorefire as follows. import UIKit import Alamofire import SwiftyJSON class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() Alamofire.request(.GET, "https://api.mynexttrainschedule.net/") .responseJSON { response in guard let object = response.result.value else { print("Oh, no!!!") return } let json = JSON(object);print(json) let schedule = json[0]["schedule"] } } } If I print json, I have a data structure like the

AlamofireImage Disk Cache not working

柔情痞子 提交于 2019-12-04 04:15:42
I want to use AlamofireImage to download images from an url and then cache it on the device disk space. I read several posts about this and found out that AlamofireImage supports this with the help of the ImageDownloader class. The most interesting information was given in this SO answer So I tried to set a custom NSURLCache for the ImageDownloader so that it would cache the images directly to the disk. I did that by setting the memory capacity to 0. Then I use this custom ImageDownloader to download an image. The folder that I specified for the disk path is created on the disk but

Cannot call value of non-function type 'NSHTTPURLResponse?' Alamofire ObjectMapper

北城以北 提交于 2019-12-04 03:13:38
问题 Cannot call value of non-function type 'NSHTTPURLResponse?' Can someone please help me here? Here is the code public func responseObject<T: Mappable>(queue: dispatch_queue_t?, keyPath: String?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, ErrorType?) -> Void) -> Self { return response(queue: queue, responseSerializer: Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)) { request, response, result in dispatch_async(dispatch_get_global_queue

Code=-1001 “The request timed out.”

回眸只為那壹抹淺笑 提交于 2019-12-04 03:12:56
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", forHTTPHeaderField: "Content-Type") request.setValue("application/json", forHTTPHeaderField: "Accept") request

Using FORM DATA with Alamofire

懵懂的女人 提交于 2019-12-04 03:07:15
I am using alamofire for some time now, but I have never used a form data Post. Now I am stuck. I have 2 params (email, password) and don't know how POST them to server. Can anyone give me an example please? And here is a sample code for Alamofire 4.0 in Swift 3.0 let url = "http://testurl.com" let parameters = [ "email": "asd@fgh.hjk", "password": "55555" ] Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default).responseJSON { response in switch response.result { case .success: if let value = response.result.value { print(value) } case .failure(let error):

How to cancel Alamofire.upload

偶尔善良 提交于 2019-12-04 02:59:46
I am uploading images on server via Alamofire.upload as multipart data. Unlike Alamofire.request it's not returning Request object, which I usually use to cancel requests. But it's very reasonable to be able to cancel such a consuming requests like uploading. What are the options for this in Alamofire? Using the Uploading MultiPartFormData example from the Alamofire README: Alamofire.upload( .POST, "https://httpbin.org/post", multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn") multipartFormData.appendBodyPart(fileURL:

Library not loaded: @rpath/Alamofire.framework/Alamofire

坚强是说给别人听的谎言 提交于 2019-12-04 02:38:54
问题 When I try to run my iOS App in Xcode in app: dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire Referenced from: /private/var/mobile/Containers/Bundle/Application/78CC9A04-53B7-49D3-9E4D-7DF0CAA41DD0/Sawasdee.app/Sawasdee Reason: image not found (lldb) What should i do? 回答1: Without knowing exactly how you have your project set up, it's difficult to give exact advice. The first thing you should do is checkout out the README of Alamofire. It has great explanations for manual set

Swift behaves differently on debug and release mode

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:17:57
Not sure if that's an issue with Swift, XCode or Alamofire but I recognized strange behavior on different places within my mixed Swift/Objc app . It only happens in parts which are written in Swift and use closures/networking. Here's an example code where it happens: Alamofire.request(.DELETE, "http://someUrl.com/user", parameters: nil) .response { (request, response, data, error) in // some cleanup code and an alert } When I run my app in Debug mode on my iPhone then it all just works , the cleanup code and the alert get presented like they should when I do the "delete account" action which

Xcode : Alamofire get String response

别来无恙 提交于 2019-12-04 00:40:19
问题 I am new in IOS development and currently learning networking with Alamofire i am trying to make a login ... whenever the credentials are correct the .php file returns a json and i am able to get that json from Alamofire through the following code: Alamofire.request(loginUrl, method: .post, parameters: parameters).responseJSON { (response:DataResponse<Any>) in print("String:\(response.result.value)") switch(response.result) { case .success(_): if let data = response.result.value{ print(self