alamofire

How to get the result value of Alamofire.request().responseJSON in swift 2?

时光怂恿深爱的人放手 提交于 2019-11-27 01:15:32
问题 I have a question about the new version of Alamofire for Swift 2 Alamofire.request(.POST, urlString, parameters: parameters as? [String : AnyObject]) .responseJSON { (request, response, result) -> Void in let dico = result as? NSDictionary for (index, value) in dico! { print("index : \(index) value : \(value)") } } In this section I would like to cast the result in to a NSDictionary. But When I compile and put a breakpoint, the debugger says that dico is nil. If I use debugDescription to

How to upload image with parameters using Alamofire in Swift

白昼怎懂夜的黑 提交于 2019-11-27 01:07:49
问题 I am developing an iPhone application with swift. and I'am using Alamofire framework for handling http requests. I use Alamofire.request for POST , GET and etc like this: Alamofire.request(.POST, myURL , parameters: ["a": "1", "b" : "2" ]) .response { (request, response, data, error) in } And I use Alamofire.upload to upload image to server this : Alamofire.upload(.POST, uploadURL , fileURL) And both works perfectly, but now I want to upload an image and also send some parameters with, and my

How to add Alamofire URL parameters

Deadly 提交于 2019-11-27 01:04:53
问题 I have a working scenario using Postman passing in URL parameters. Now when I try to do it via Alamofire in Swift, it does not work. How would you create this url in Alamofire? http://localhost:8080/?test=123 _url = "http://localhost:8080/" let parameters: Parameters = [ "test": "123" ] Alamofire.request(_url, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers 回答1: The problem is that you're using URLEncoding.default . Alamofire interprets URLEncoding

Alamofire: Sending JSON as request parameter

纵饮孤独 提交于 2019-11-26 23:41:32
问题 I have an incredibly long array and string I want to send through Alamofire though I don't know how I would send raw JSON as a parameter. The JSON looks a little like { "skus":["8865594-CS,4387296-CS,1175540-CS...."], "listType": "H" } Instead of getting that to behave like a Swift array and then serializing, is there a way I can pass this JSON as a parameter in Alamofire? Thanks! Edit: I was able to pull a bit of magic in a text editor to get the params formatted in the style of a Swift

How to upload audio with Alamofire multipart upload?

孤人 提交于 2019-11-26 23:40:28
问题 I want to upload and audio file with using Alamofire . I see other questions which are telling to use Multipart request to do that Here is the example i got form other question : Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(audioRecorder?.url, withName: "iosTest.mp3") //**this "withName:" is it the name of the file? }, to: "https://yourLinkGoesHere", encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload

Swift variable name with ` (backtick)

血红的双手。 提交于 2019-11-26 22:00:21
问题 I was browsing Alamofire sources and found variable which name is backtick escaped in this source file open static let `default`: SessionManager = { let configuration = URLSessionConfiguration.default configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders return SessionManager(configuration: configuration) }() However in places where variable is used there are no backticks. What's the purpose of backticks? 回答1: According to the Swift documentation : To use a reserved word as

Returning a value from a function with Alamofire and SwiftyJson

丶灬走出姿态 提交于 2019-11-26 21:58:57
问题 I have an app that returns a menu of information (basically menus, menu_headers, and items). I'd like to have something like this: EKMenu.getMenu(menu_id: Int) that would return a menu but I think I would need a completion handler in here. I currently have: class func getMenu(menu_id: Int){ //class func getMenu(menu_id: Int, completionHandler:(NSArray -> Void)){ let url="https://www.example.com/arc/v1/api/menus/\(menu_id)/mobile" Alamofire.request(.GET, url).responseJSON() { (_, _, data, _)

Error Domain=NSPOSIXErrorDomain Code=100 “Protocol error”

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 20:55:14
问题 I am trying to call a service using Alamofire using a .get method. The request has nothing special no parameters just an Authorization header. I am going a bit mad here because to request works fine when I run it on postman with the same URL and Authorization token, but when I run my app code with Alamofire it returns this error: Error Domain=NSPOSIXErrorDomain Code=100 "Protocol error" UserInfo={NSErrorPeerAddressKey={length = 16, capacity = 16, bytes = 0x100201bbd83ad0b10000000000000000},

POST request with data in body with Alamofire 4

旧城冷巷雨未停 提交于 2019-11-26 20:37:12
问题 how is it possible to send a POST request with a data in the HTTP body with Alamofire 4? I used custom encoding at swift 2.3 it was working good. I converted my code swift 3 and I tried to paramater encoding but not working. This code : public struct MyCustomEncoding : ParameterEncoding { private let data: Data init(data: Data) { self.data = data } public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { var urlRequest = try urlRequest

iOS 9.3 : An SSL error has occurred and a secure connection to the server cannot be made

我只是一个虾纸丫 提交于 2019-11-26 19:41:06
问题 I am getting following error with self signed certificate Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made. while testing web-services for one of my demo app with iOS 9.3 XCode 7.3 Swift 2.2 Alamofire 3.3.0 and Local server : https://filename.hostname.net Note: before assuming its Duplicate, I would request please read it all the way,even same i have reported to apple dev forums Using Alamofire Library func