alamofire

How to use SwiftyJSON on nested JSON values

…衆ロ難τιáo~ 提交于 2019-12-01 18:19:40
问题 I'm calling a JSON API that has several nested values that I need to get. I'm using SwiftyJSON to make things a little cleaner. For the top level values, everything seems to be working fine, but on anything deeper, I'm getting the dreaded "nil when unwrapping optional value." Here is how I'm making the API call with Alamofire: Alamofire.request(APIRequests.Router.Nearby(self.page)).responseJSON(){ (_,_,json,_) in println(json) if (json != nil){ var jsonObj = JSON(json!) if let userArray =

Return Bool in Alamofire closure

余生颓废 提交于 2019-12-01 18:12:06
I use Swift 2 and Xcode 7.1. I have a function who connect my users, but it will connect at my database with HTTP. I use Alamofire for execute this request. I want to know, from a view controller if the user is connected. I have my function connect in a class. And i test connection in a ViewController. Like this : class user { // ... func connectUser(username: String, password: String){ let urlHost = "http://localhost:8888/project350705/web/app_dev.php/API/connect/" let parametersSymfonyG = [ username, password ] let url = UrlConstruct(urlHost: urlHost).setSymfonyParam(parametersSymfonyG)

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

帅比萌擦擦* 提交于 2019-12-01 17:10:11
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(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let parsedObject = Mapper<T>().map(keyPath != nil ? result.value?

Unescaped control character around character 981.Error while parsing JSON

自作多情 提交于 2019-12-01 16:42:48
问题 Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 981." UserInfo={NSDebugDescription=Unescaped control character around character 981.} I am getting above error in response of request. Below are lines of code: Alamofire.request(.POST, urlStr, parameters: parameter, encoding: .JSON, headers: nil).validate().responseJSON { response in switch response.result { case .Success(let JSON): completionHandler(JSON as! NSDictionary) case.Failure(let Error): print

how to pass a nil value for one of the parameter in alamofire Post request

元气小坏坏 提交于 2019-12-01 15:36:25
I would like to pass a nil value i.e., optional to one of the parameter value. And it must proceed with the nil value in the Alamofire Post request .It would be helpful if you tell me how to proceed next? let image: UIImage = UIImage() let imageData = UIImagePNGRepresentation(image) let base64String = imageData?.base64EncodedStringWithOptions(.Encoding64CharacterLineLength) let parameters = [ "first_name": "XXXXX", "email" : "1234@gmail.com", "password" : "password", "profile_picture" : base64String] Alamofire.request(.POST, "http://abc/public/user/register", parameters: parameters, encoding:

how to pass a nil value for one of the parameter in alamofire Post request

做~自己de王妃 提交于 2019-12-01 15:19:04
问题 I would like to pass a nil value i.e., optional to one of the parameter value. And it must proceed with the nil value in the Alamofire Post request .It would be helpful if you tell me how to proceed next? let image: UIImage = UIImage() let imageData = UIImagePNGRepresentation(image) let base64String = imageData?.base64EncodedStringWithOptions(.Encoding64CharacterLineLength) let parameters = [ "first_name": "XXXXX", "email" : "1234@gmail.com", "password" : "password", "profile_picture" :

Alamofire 2.0 and Swift 2 - Header is not working. See how to fix it

北城以北 提交于 2019-12-01 14:30:34
When I upgraded my project to swift 2 with Alamofire 2 headers stopped working without any errors in code. The reason is that headers are not working old style. // login with Alamofire 1 and Swift 1.2 - WITH HEADER func loginAlamofire_1(username:String) { manager.session.configuration.HTTPAdditionalHeaders = ["Authorization": "yourToken"] manager.request(.POST, "login_url", parameters: ["username" : username], encoding: ParameterEncoding.JSON) .response{ (request, response, data, error) -> Void in if error != nil{ print("error!") } else { print("welcome") } } } You can see the fixed version

Multiple file upload with array of parameters using Alamofire

╄→гoц情女王★ 提交于 2019-12-01 13:59:04
i have array of parameters and array of images each set of parameter contain one and only one image.my code let imgData = UIImageJPEGRepresentation(imageView.image!, 0.2)! Alamofire.upload(multipartFormData: { multipartFormData in multipartFormData.append(imgData, withName: "fileset",fileName: "file.jpg", mimeType: "image/jpg") for (key, value) in params { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } }, to:URLUpdateProfile, method:.post, headers:headers) { (result) in switch result { case .success(let upload, _, _): upload.uploadProgress(closure: {

AlamofireObjectMapper not supporting ios8 when updating to swift 3?

混江龙づ霸主 提交于 2019-12-01 13:46:32
I tried to update my project to Swift 3, my project has support for ios8 as well. While trying to update the cocoapods, I am getting issue that AlamofireObjectMapper requires higher deployment target. On changing to ios9 the pods install without any error, but I still want to support ios8. Can anyone help on how this can be achieved? Thanks in advance. EDIT Alamofire 4.1.0 Support for iOS 8.0 and macOS 10.10 is back! You cannot update to Swift 3 without dropping support for iOS 8, I'm afraid. The reason is that the Swift 3 version of Alamofire is 4.0 and the developers have decided to drop

Why upload alamofire background request don't executes in background?

六月ゝ 毕业季﹏ 提交于 2019-12-01 13:16:05
I use alamofire in order to upload 30 mb zip file to server here is my request let configuration = URLSessionConfiguration.background(withIdentifier: "identifire.com") alamoFireManager = Alamofire.SessionManager(configuration: configuration) let tempZipFilePath = UtilDirectory.tempZipPath.tweak() alamoFireManager.upload(URL(fileURLWithPath: tempZipFilePath), to: deligate.url, method: .post, headers: headers) .uploadProgress(closure: { progress in print("Upload Progress: \(progress.fractionCompleted)") }) .validate() .responseJSON {} When request is starting I can see upload progress