Tag: alamofire

Swift Alamofire VS AFNetworking

我正在使用Swift开发一个应用程序。 我想调用一个REST API。 我发现有两个stream行的图书馆,AFNetworking和Alamofire。 但是我不知道哪个更好(更受欢迎或者有更多的function)。 有谁能提出Alamofire和AFNetworking之间的主要区别是什么?

在这种情况下,“方法”对于types查找是不明确的,在Alamofire中是错误的

我正在使用Alamofire进行networking处理,遇到一个奇怪的错误。 看来我们不能通过Method enum作为参数。 [错误在方法参数上] private func apiRequest(method: Method, url: String, apiData: [String : AnyObject], completion:(finished: Bool, response: AnyObject?) ->Void) { Alamofire.request(method, url, parameters: apiData).responseJSON{ response in if let JSON = response.result.value { completion(finished: true, response: JSON) } else { completion(finished: false, response:nil) } } }

什么是Xcode中的embedded式二进制文件?

我在Swift项目中使用Alamofire ,部分手动安装说明是在我的应用程序目标的General选项卡的Embedded Binaries下添加Alamofire。 什么是embedded式二进制文件 ?

如何快速发送POST请求与BODY

我试图用Alamofire快速地提出一个请求。 我的JSON身体看起来像: { "IdQuiz" : 102, "IdUser" : "iosclient", "User" : "iosclient", "List":[ { "IdQuestion" : 5, "IdProposition": 2, "Time" : 32 }, { "IdQuestion" : 4, "IdProposition": 3, "Time" : 9 } ] } 我试图let list与NSDictionnary看起来像: [[Time: 30, IdQuestion: 6510, idProposition: 10], [Time: 30, IdQuestion: 8284, idProposition: 10]] 我的请求使用Alamofire看起来像: Alamofire.request(.POST, "http://myserver.com", parameters: ["IdQuiz":"102","IdUser":"iOSclient","User":"iOSClient","List":list ], […]

AlamoFire不尊重超时间隔

class APIClient { var user = User() let alamoFireManager : Alamofire.Manager? let center = NSNotificationCenter.defaultCenter() init(){ let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.timeoutIntervalForRequest = 4 // seconds configuration.timeoutIntervalForResource = 4 self.alamoFireManager = Alamofire.Manager(configuration: configuration) } func test(){ //This does not respect the 4 second time out. Why? self.alamoFireManager!.request(.POST, CONSTANTS.APIEndpoint+"/test", parameters: parameters).responseJSON { (req, res, json, error) in […]

Swift 3 Alamofire分段上传

由于迁移到Swift 3,我发现很难编译使用Alamofire的项目。 上传multipartFormData时发生问题: Alamofire.upload(.POST, URL, headers: headers, multipartFormData: { multipartFormData in . . . }) 模糊引用成员上传(_:to:method:headers :)' 任何帮助非常感谢,提前致谢! 解决: Alamofire.upload(multipartFormData: { (multipartFormData) in multipartFormData.append(fileData, withName: "file_pack", fileName: "file_pack", mimeType: "text/plain") for (key, value) in self.parameters { multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key) } }, with: URL2, encodingCompletion: { (result) in switch result { case .success(let upload, _, […]

如何使用Alamofire自定义标题

我刚刚开始看看Mattt的新Alamofire swiftnetworking库,我不太确定如何使用自定义头文件。 我试图从AFNetworking转换到Alamofire的代码是这样的: let request = NSMutableURLRequest(URL: url) request.setValue(authorizationToken, forHTTPHeaderField:"Authorization")

通过Alamofire发送json数组

我想知道是否有可能直接发送一个数组(不包装在字典中)的POST请求。 显然parameters参数应该得到一个映射:[String:AnyObject]? 但是我想能够发送下面的例子json: [ "06786984572365", "06644857247565", "06649998782227" ]

Cocoapods +无法加载“x”的底层模块

我正在运行Xcode 7,Swift 2.0,iOS 9。 我想使用Cocoapods在我的项目中安装Alamofire。 我做了以下几件事: gem install cocoapods pod setup pod init 更新Podfile到: # Uncomment this line to define a global platform for your project # platform :ios, '9.0' use_frameworks! target 'JSONeg' do pod 'Alamofire', :branch => 'swift-2' end 然后我安装了pod: pod install 我添加了以下ViewController.swift import Alamofire 这引发了以下错误: Cannot load underlying module for 'Alamofire' 我testing了另一个吊舱,并提出了相同的错误,所以我想问题是与安装Cocoapods。 任何帮助将不胜感激。

与Alamofire的NSURLSession并发请求

我正在使用我的testing应用程序遇到一些奇怪的行为。 我有大约50个同时发送到同一个服务器的GET请求。 服务器是一个embedded式服务器上的一小部分硬件资源非常有限。 为了优化每个请求的性能,我configuration一个Alamofire.Manager实例如下: let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.HTTPMaximumConnectionsPerHost = 2 configuration.timeoutIntervalForRequest = 30 let manager = Alamofire.Manager(configuration: configuration) 当我通过manager.request(…)发送请求时,它们会以2对的forms发送(如预期的那样,使用Charles HTTP Proxy进行检查)。 奇怪的是,所有在第一个请求30秒内没有完成的请求,由于同时超时而被取消(即使它们还没有被发送)。 下面是一个展示行为的例子: 这是一个预期的行为,我怎样才能确保请求不会得到超时之前,他们甚至被发送? 非常感谢!