草庐IT

Alamofire

全部标签

ios - 打印 Alamofire 请求正文

我正在使用Alamofire库连接iOs中的API。我在其中一个连接中遇到问题,我不知道是因为正文中编码的数据还是其他原因。为了检测我的错误,我尝试在控制台中打印请求正文以检查我是否发送了正确的数据结构。我的代码如下:funcupdateUser(#user:User,completionHandler:(responseObject:User?,error:AnyObject?)->()){letparameters=["_id":"\(user._id!)","email":"\(user.email!)","media":"\(Mapper().toJSONArray(user.

带`(反引号)的 Swift 变量名

我在浏览Alamofire源代码时发现一个在thissourcefile中被反引号转义的变量名openstaticlet`default`:SessionManager={letconfiguration=URLSessionConfiguration.defaultconfiguration.httpAdditionalHeaders=SessionManager.defaultHTTPHeadersreturnSessionManager(configuration:configuration)}()但是在使用变量的地方没有反引号。反引号的目的是什么?删除反引号会导致错误:Keyw

带`(反引号)的 Swift 变量名

我在浏览Alamofire源代码时发现一个在thissourcefile中被反引号转义的变量名openstaticlet`default`:SessionManager={letconfiguration=URLSessionConfiguration.defaultconfiguration.httpAdditionalHeaders=SessionManager.defaultHTTPHeadersreturnSessionManager(configuration:configuration)}()但是在使用变量的地方没有反引号。反引号的目的是什么?删除反引号会导致错误:Keyw

ios - 总是得到构建错误 : No such module 'Alamofire'

我遵循了github中Alamofire的说明|,我创建了一个名为cocoapods-test的xcode项目并关闭了它。我转到项目文件夹运行podinit命令生成一个Podfile。然后我在Podfile中添加了以下代码:source'https://github.com/CocoaPods/Specs.git'platform:ios,'8.0'use_frameworks!pod'Alamofire','~>3.0'然后,我运行命令podinstall,这是terminal:中的结果UpdatinglocalspecsrepositoriesCocoaPods1.0.0.beta

ios - 总是得到构建错误 : No such module 'Alamofire'

我遵循了github中Alamofire的说明|,我创建了一个名为cocoapods-test的xcode项目并关闭了它。我转到项目文件夹运行podinit命令生成一个Podfile。然后我在Podfile中添加了以下代码:source'https://github.com/CocoaPods/Specs.git'platform:ios,'8.0'use_frameworks!pod'Alamofire','~>3.0'然后,我运行命令podinstall,这是terminal:中的结果UpdatinglocalspecsrepositoriesCocoaPods1.0.0.beta

ios - 使用 retryWhen 根据 http 错误代码更新 token

我在Howtorefreshoauthtokenusingmoyaandrxswift上找到了这个例子我不得不稍微改变一下才能编译。此代码对我的场景有效80%。它的问题是它会针对所有http错误运行,而不仅仅是401错误。我想要的是将所有其他http错误作为错误传递,这样我就可以在其他地方处理它们,而不是在这里吞下它们。使用这段代码,如果我得到HttpStatus500,它会运行3次验证码,这显然不是我想要的。我试图更改此代码以仅处理句柄401错误,但似乎无论我做什么我都无法编译代码。它总是提示错误的返回类型,"CannotconvertreturnexpressionoftypeOb

ios - 使用 retryWhen 根据 http 错误代码更新 token

我在Howtorefreshoauthtokenusingmoyaandrxswift上找到了这个例子我不得不稍微改变一下才能编译。此代码对我的场景有效80%。它的问题是它会针对所有http错误运行,而不仅仅是401错误。我想要的是将所有其他http错误作为错误传递,这样我就可以在其他地方处理它们,而不是在这里吞下它们。使用这段代码,如果我得到HttpStatus500,它会运行3次验证码,这显然不是我想要的。我试图更改此代码以仅处理句柄401错误,但似乎无论我做什么我都无法编译代码。它总是提示错误的返回类型,"CannotconvertreturnexpressionoftypeOb

ios - Alamofire 网络调用未在后台线程中运行

据我了解,默认情况下,Alamofire请求在后台线程中运行。当我尝试运行这段代码时:letproductsEndPoint:String="http://api.test.com/Products?username=testuser"Alamofire.request(productsEndPoint,method:.get).responseJSON{responsein//checkforerrorsguardresponse.result.error==nilelse{//gotanerroringettingthedata,needtohandleitprint("Insid

ios - Alamofire 网络调用未在后台线程中运行

据我了解,默认情况下,Alamofire请求在后台线程中运行。当我尝试运行这段代码时:letproductsEndPoint:String="http://api.test.com/Products?username=testuser"Alamofire.request(productsEndPoint,method:.get).responseJSON{responsein//checkforerrorsguardresponse.result.error==nilelse{//gotanerroringettingthedata,needtohandleitprint("Insid

swift - 如何检索请求的 Alamofire 响应 header

如何检索请求的响应header?以下是我提出的要求。Alamofire.request(.GET,requestUrl,parameters:parameters,headers:headers).responseJSON{responseinswitchresponse.result{case.Success(letJSON):...case.Failure(leterror):...}提前致谢! 最佳答案 如果响应是NSHTTPURLResponse类型,您可以从response.allHeaderFields获取header。