alamofire

iOS - Alamofire 网络请求

感情迁移 提交于 2020-02-21 05:45:15
前言 Alamofire 是 Swift 语言的 HTTP 网络开发工具包,相当于 Swift 实现 AFNetworking 版本。当然,AFNetworking 非常稳定,在 Mac OSX 与 iOS 中也能像其他 Objective-C 代码一样用 Swift 编写。不过 Alamofire 更适合 Swift 语言风格习惯(Alamofire 与 AFNetworking 可以共存一个项目中,互不影响)。Alamofire 取名来源于 Alamo Fire flower。 Alamofire 的核心主要是试图简化 iOS 中 HTTP 网络连接,它通过使用 NSURLSession 以及 Foundation URL Loading System 来创建一个 Swift 本地的网络访问接口,从而实现令人难以置信效率的任务。 1、Alamofire Alamofire 功能: Chainable Request / Response methods URL / JSON / plist Parameter Encoding Upload File / Data / Stream Download using Request or Resume data Authentication with NSURLCredential Progress Closure &

Alamofire 的使用

笑着哭i 提交于 2020-02-21 05:43:11
最近,AFNetworking 的作者 Mattt Thompson 提交了一个新的类似于 AFNetworking 的网络 基础库,并且是专门使用最新的 Swift 语言来编写的,名为: Alamofire AFNetwork 的前缀 AF 是 Alamofire 的缩写,因此这个新的库名称其实是根据 Swift 的约定来进行命名的。 在本教程的第一部分中,我们将带领大家使用 Alamofire 来制作一个图片库应用,其来源是 500px.com 。在这个过程中,您可以学习到如何使用 Alamofire 中的重要组件,以及了解在应用中处理网络请求的某些重要的知识点。 本教程的第二部分将基于第一部分所制作的应用,并为其增加一些好用的功能。您可以通过这个过程学习到更多高级的 Alamofire 用法。 本教程假定您已熟悉 Swift 语言以及 iOS 开发。如果不是的话,请参阅我们的 其他教程 。还有,本教程使用 Xcode 6.1 作为开发环境(而不是 Xcode 6.2 beta)。 > 提示: 如果您已经熟悉了 Alamofire 的基本用法,那么您可以直接跳到本文的 第二部分 。但是请确保您已拥有消费者密钥(cunsumer key),然后参照下文在应用中替换它。 让我们开始吧 首先下载本次教程的 初始项目 。这个项目中提供了在本教程中需要的全部 UI

Right Way for changing timeoutIntervalForRequest in Alamofire

对着背影说爱祢 提交于 2020-02-15 08:38:14
问题 I changed timeoutIntervalForRequest with let manager = Alamofire.SessionManager.default manager.session.configuration.timeoutIntervalForRequest = 3 manager.request(url).response {} but seems not worked, Any suggestion? 回答1: 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

Right Way for changing timeoutIntervalForRequest in Alamofire

时间秒杀一切 提交于 2020-02-15 08:37:46
问题 I changed timeoutIntervalForRequest with let manager = Alamofire.SessionManager.default manager.session.configuration.timeoutIntervalForRequest = 3 manager.request(url).response {} but seems not worked, Any suggestion? 回答1: 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

Swift 3.0, Alamofire 4.0 Extra argument 'method' in call

…衆ロ難τιáo~ 提交于 2020-02-10 04:23:49
问题 I have read all the questions on this issue this and this. I have the following code let fullURL = God.getFullURL(apiURL: self.apiUrl) if (getOrPost == God.POST) { Alamofire.request(fullURL, method: .POST, AnyObject: self.postData?, encoding:.JSONEncoding.default, headers: nil).responseJSON{ response in self.responseData = response.result.value } } else if (getOrPost == God.GET) { Alamofire.request(fullURL, method : .GET, Parameters: getData, encoding:.JSONEncoding.default, headers: nil)

swift 3 completion handler to return string

五迷三道 提交于 2020-02-08 10:33:30
问题 I am new at swift and got problem with getting string from function, I am trying to use completion handler, but something is wrong, could you help me? After adding [String : String] to func, I cant get rezult, I want to get response and print it. Error: Cannot convert return expresion of type () to return type [String : String] Requests: public func login(userName: String, password: String) -> [String : String]{ let loginrequest = JsonRequests.loginRequest(userName: userName, password:

how to set protocol function not properly invoke in DataProvider class Alamofire function swift

筅森魡賤 提交于 2020-02-06 08:01:40
问题 I need to set protocol function in Alamofire download function to track and observe progress fraction value. I have to tried to implement delegate function but its not properly executes giving error. I have one DataProvider class which has Alamofire function and then I am calling this in ViewController. Errors getting on init(webService: DataProvider = DataProvider()) : 'self' used before 'super.init' call 'super.init' isn't called on all paths before returning from initializer ViewController

how to set protocol function not properly invoke in DataProvider class Alamofire function swift

纵然是瞬间 提交于 2020-02-06 08:00:30
问题 I need to set protocol function in Alamofire download function to track and observe progress fraction value. I have to tried to implement delegate function but its not properly executes giving error. I have one DataProvider class which has Alamofire function and then I am calling this in ViewController. Errors getting on init(webService: DataProvider = DataProvider()) : 'self' used before 'super.init' call 'super.init' isn't called on all paths before returning from initializer ViewController

Why alamofire downloads progress in alert will flashing and the behind screen starts to be fade to black?

喜你入骨 提交于 2020-02-05 04:55:05
问题 I have progress view in alert when downloading with alamofire, but the problem is that when I want to download the progress view in alert will start to be complete but flashing and the other problem is that the behind screen will start to be fade to black I think in every second a new alert with progress view will show and at the end there are lots of alerts how can I avoid them? downloadTimer = Timer.scheduledTimer(timeInterval: 1 , target: self, selector: #selector(flashingDownload),

Cannot invoke 'append' with an argument list of type '(String, withName: String)' in Alamofire 4.0

蹲街弑〆低调 提交于 2020-02-04 01:35:38
问题 I'm using Alamofire 4.0 to upload video to server after select or record it through device/camera but when I'm trying to call upload function with append , this error appeared to me in all append statement , what is the wrong in my code. the second my question about if I want to display progress with percentage of progress during upload how I can make that through Alamofire. Thanks :) My code after reading url of selected/recorded video func imagePickerController(_ picker: