alamofire

Linking error in unit test using URLRequestConvertible

心不动则不痛 提交于 2019-12-02 01:04:17
I have a weird problem writing a simple unit test (Xcode 7.2) for a very simple function which makes sure a parameter is added to a URL: func appendToken(token: String, toRequest request: URLRequestConvertible) throws -> URLRequestConvertible { var error: NSError? let modifiedRequest: NSMutableURLRequest (modifiedRequest, error) = Alamofire.ParameterEncoding.URL.encode(request, parameters: ["token": self.token]) guard error == nil else { // TODO: handle error throw error! } return modifiedRequest } The unit test is like this: func testTokenAddition() { let token = "ABCD12345" let client =

Swift iOS 9 NSURLErrorDomain Error -1004

╄→гoц情女王★ 提交于 2019-12-02 00:53:03
I'm using Swift 2 and Alamofire with both iOS 9 and iOS 8. In iOS 8 all my requests to my API work fine. In iOS 9 they immediately fail with a -1004 NSURLErrorDomain with the message "Could not connect to the server.". I read about Apple's change with App Transport Security and already added the entry to my Plist to disable it and allow insecure connections. I'm at a loss as to the reason for this error...any help would be great! After messing around with a ton of different keys and values to make it work, I finally have come up with this to make it function in iOS9.1: <key

Alamofire custom parameters

落爺英雄遲暮 提交于 2019-12-02 00:52:27
I am trying to convert this curl call to Alamofire in Swift. curl -X POST https://content.dropboxapi.com/2/files/download --header "Authorization: Bearer ab-xxx-x-x" --header "Dropbox-API-Arg: {\"path\": "/acme101/acmeX100/acmeX100.001.png\"}" And I figured this ... let headers:HTTPHeaders = ["Authorization": "Bearer " + token2Save] let moreheaders:Parameters = ["Dropbox-API-Arg": ["path":sourcePath]] Alamofire.request("https://content.dropboxapi.com/2/files/download", parameters: moreheaders, encoding: URLEncoding(destination: .queryString), headers: headers).responseJSON { feedback in guard

How to upload MultipartFormData with authentication using Alamofire

爱⌒轻易说出口 提交于 2019-12-02 00:41:35
How to upload MultipartFormData with authentication using Alamofire? The part that I don't understand is where to put .authenticate(user: username, password: password). ? This is how I usually upload pictures using MultipartFormData : Alamofire.upload( .POST, "https://myExampleUrl/photo/upload", headers: headers, multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(data: "default".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"_formname") multipartFormData.appendBodyPart(fileURL: fileUrl, name: "photo") }, encodingCompletion: {

alamofire multipartformdata use urlrequest

送分小仙女□ 提交于 2019-12-01 23:20:31
问题 I want to use Alamo fire multipart form data use request, for example, I use upload API let profile = self.photoView.imageView?.image let parameters : [String:String] = [ "homePageUrl": webURLField.text!, "nickName": nickNameField.text!, "selfIntro": introField.text!, ] let uri = Constants.APIURL.changeProfile let fileName = "\(nickNameField.text!).jpg" Alamofire.upload(multipartFormData: { (multipartFormData) in if let imageData = UIImageJPEGRepresentation(profile!, 1.0) { multipartFormData

Right Way for changing timeoutIntervalForRequest in Alamofire

江枫思渺然 提交于 2019-12-01 21:54:15
I changed timeoutIntervalForRequest with let manager = Alamofire.SessionManager.default manager.session.configuration.timeoutIntervalForRequest = 3 manager.request(url).response {} but seems not worked, Any suggestion? This worked for me :) let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = TimeInterval(7) configuration.timeoutIntervalForResource = TimeInterval(7) let session = URLSession(configuration: configuration) let task = session.dataTask(with: url) {} Changes to the configuration of an already initialized URLSession have no effect, per Apple's

Cannot install Alamofire 4.0 in Xcode 8.0 Using CocoaPods

时光怂恿深爱的人放手 提交于 2019-12-01 20:49:33
I need to upgrade one project to Swift 3.0, that has some libraries by Cocodpods. So, I've removed all links related with Cocoapods and recreate pod file using pod init and upgrade some version of library such as AlamorFire. But pod install said [!] Unable to satisfy the following requirements: - `Alamofire (~> 4.0)` required by `Podfile` None of your spec sources contain a spec satisfying the dependency: `Alamofire (~> 4.0)`. You have either: * out-of-date source repos which you can update with `pod repo update`. * mistyped the name or version. * not added the source repo that hosts the

making an asynchronous alamofire request synchronous

三世轮回 提交于 2019-12-01 20:15:41
问题 I am attempting to perform an alamofire post request in swift func checkIfUserExistsInDB(userName: String) -> NSString { print ("IN") var info: NSString = "" Alamofire.request(.POST, "http://blablabla.com/getuserdata", parameters: ["queryValue": userName,], encoding:.JSON).responseJSON { request, response, result in switch result { case .Success(let JSON): info = NSString(data: JSON.dataUsingEncoding(NSUTF8StringEncoding)!, encoding: NSUTF8StringEncoding)! case .Failure(let data, _): print (

making an asynchronous alamofire request synchronous

我们两清 提交于 2019-12-01 18:30:45
I am attempting to perform an alamofire post request in swift func checkIfUserExistsInDB(userName: String) -> NSString { print ("IN") var info: NSString = "" Alamofire.request(.POST, "http://blablabla.com/getuserdata", parameters: ["queryValue": userName,], encoding:.JSON).responseJSON { request, response, result in switch result { case .Success(let JSON): info = NSString(data: JSON.dataUsingEncoding(NSUTF8StringEncoding)!, encoding: NSUTF8StringEncoding)! case .Failure(let data, _): print ("IN") if let data = data { info = (NSString(data: data, encoding: NSUTF8StringEncoding)!) print (info) }

How to use SwiftyJSON on nested JSON values

一笑奈何 提交于 2019-12-01 18:19:45
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 = jsonObj ["results"].array { for userDict in userArray { var username: String! = userDict["username"]