alamofire

Swift Alamofire add custom header to all requests

倖福魔咒の 提交于 2019-12-30 08:35:27
问题 I tried to add custom header with this: let manager = Manager.sharedInstance manager.session.configuration.HTTPAdditionalHeaders = [ "Authorization": "Token \(token)" ] But it doesn't work, what am i doing wrong? I need to add this after login, so that header will be used in all requests. 回答1: A way to do this is to use a RequestAdapter as demoed on the Alamofire advanced usage documentation. 回答2: I don't know where you do that but my AlomoFire requests look like : Alamofire.request(.GET,

Alamofire: [Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-999 “cancelled”

别来无恙 提交于 2019-12-30 08:24:15
问题 The service I'm connecting to is using a self signed certificate. For dev purposes I do not want to validate that chain. Using swift 3 with Alamofire 4. Fixed the ATS accordingly: <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>url.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict> Code to connect and disable evaluation.

numberOfRowsInSection is called before Alamofire connection

不羁的心 提交于 2019-12-30 07:17:10
问题 I get data by Alamofire in viewDidLoad , then put it into answerArray. However, before Alamofire connection, the numberOfRowsInSection is invoked and returns 0. How can I get data by Alamofire first, then get eventArray.count at numberOfRowsInSection ? var answerArray = NSMutableArray() override func viewDidLoad() { let parameters = [ "id":questionNum ] Alamofire.request(.POST, "http://localhost:3000/api/v1/questions/question_detail",parameters: parameters, encoding: .JSON) .responseJSON {

Understanding swift Alamofire completionHandler

亡梦爱人 提交于 2019-12-30 06:37:21
问题 I have these two methods in my API class to get data from an API: func authenticateUser(completionHandler: (responseObject: String?, error: NSError?) -> ()) { makeAuthenticateUserCall(completionHandler) } func makeAuthenticateUserCall(completionHandler: (responseObject: String?, error: NSError?) -> ()) { Alamofire.request(.GET, loginUrlString) .authenticate(user: "a", password: "b") .responseString { request, response, responseString, responseError in completionHandler(responseObject:

Using disk cached images if present in Alamofire Images

与世无争的帅哥 提交于 2019-12-30 06:14:09
问题 I'm using the AlamofireImage library to cache downloaded images. Code: import UIKit import AlamofireImage class ViewController: UIViewController { @IBOutlet weak var firstImageView: UIImageView! @IBOutlet weak var secondImageView: UIImageView! let downloader = ImageDownloader() let URLRequest = NSURLRequest(URL: NSURL(string: "https://httpbin.org/image/jpeg")!) override func viewDidLoad() { super.viewDidLoad() requestFirstImage() } func requestFirstImage() { downloader.downloadImage

How to add parameter to Almofire request

瘦欲@ 提交于 2019-12-30 03:35:29
问题 Disclaimer: I'm new to iOS programming, so this question is probably as simple as it looks. It's not a trick question! I've a Swift project that uses Almofire to send HTTP requests. I want to add a parameter to the query string for every single request made. So, I want to add mykey=myval to every request. EG: http://example.com/index -> http://example.com/index?mykey=myval EG: http://example.com/index?key=val -> http://example.com/index?key=val&mykey=myval I have found that all requests seem

Alamofire No Such Module (CocoaPods)

我是研究僧i 提交于 2019-12-30 02:36:15
问题 Using Xcode 7 I am trying to install Alamofire in a sample project. Have used the instructions from Ray Wenderlich's page Only change from above link is the podfile -- which is from GitHub page here because the version has been updated. I have also used the Swift 2.0 branch. Below is the snapshop of the error, my pod file and my terminal post installing the pod PODFILE TERMINAL P.S: I want to use cocoapods to install Alamofire. I don't want to download it from github page 回答1: Try this one.

How to set Cookies in alamofire?

99封情书 提交于 2019-12-30 02:22:45
问题 How to set Cookies in Alamofire such that such that every time I kill the app and restart it, the same cookie is sent? 回答1: Swift 3.0 let cookies = HTTPCookie.cookies(withResponseHeaderFields: response.allHeaderFields , for: response.URL!) Alamofire.Manager.sharedInstance.session.configuration.HTTPCookieStorage?.setCookies(cookies, forURL: URL, mainDocumentURL: nil) Alamofire instance is shared singleton, so for all Request the cookie is set. Hope it's works for you. 回答2: Get cookies from

Module file was created by an older version of the compiler

我与影子孤独终老i 提交于 2019-12-29 04:30:06
问题 Using Carthage to manage my dependencies, everything runs fine in the simulator. However, when building for a device I get the following error: Module File was created by an older version of the compiler; rebuild Alamofire and try again: .../DerivedData/Build/Products/Debug-iPhones... I have tried what others suggested to similar issues: deleting my derived data, reinstalling Carthage and rebuilding the frameworks. However, the error has been persistent. 回答1: Are you using the right version

Swift 3 - Alamofilre 4.0 multipart image upload with progress

随声附和 提交于 2019-12-28 06:15:06
问题 I've done with image upload and its successfully uploaded on server using below method. Now I want to upload image with its progress so can any one tell me how to do? I found on everywhere but didn't got the correct solution. Code for image upload without it's progress : @IBAction func uploadClick(_ sender: AnyObject) { // define parameters let parameters = [ "file_name": "swift_file.jpeg" ] Alamofire.upload(multipartFormData: { (multipartFormData) in multipartFormData.append