草庐IT

AlamoFire

全部标签

Swift 3 - 如何将回调函数定义为参数

想用Alamofire创建全局http请求函数/扩展就像是functionRequest(requestPath:String,requestParams:Any,onComplate:Void){//stuffhere,whenasyncrequestcomplateiwanttocallonComplatefunction//likeC#method.Invoke()orfunc.Invoke()} 最佳答案 你可以只传递闭包(函数)作为参数swiftfuncrequest(requestPath:String,requestP

ios - 仅在 GET 请求上出现 Alamofire 请求错误

我正在努力将我的项目从AFNetworking转移到Alamofire。真的很喜欢这个项目。POST请求工作正常,但是,我在尝试发出GET请求时收到此错误。下面是一些示例代码:classfunclistCloudCredntials(onlyNewonlyNew:Bool=true,includePending:Bool=true)->Request{letparameters:[String:AnyObject]=includePending?["include_pending":"true"]:[:]leturlString="https://myapp-staging.herok

ios - Alamofire 4 多部分请求上传进度

我应该如何使用Alamofire4跟踪我的分段上传请求的进度?我的encodingCompletion处理程序:encodingCompletion:{encodingResultinswitchencodingResult{case.success(letuploadRequest,_,_):uploadRequest.uploadProgress{pinprint(p.completedUnitCount,p.totalUnitCount)}breakcase.failure(_):print("Failedtoencodeupload")}}我得到的错误是:Cannotcallv

ios - 在 Swift iOS 9.3 中检查慢速(不仅仅是设备已连接)互联网连接

当互联网连接速度非常慢时,我在处理这个案例时遇到了一些麻烦。首先,让我解释一下。当设备未连接到Internet时我可以处理,处理的功能是:publicclassReachability{classfuncisConnectedToNetwork()->Bool{varzeroAddress=sockaddr_in(sin_len:0,sin_family:0,sin_port:0,sin_addr:in_addr(s_addr:0),sin_zero:(0,0,0,0,0,0,0,0))zeroAddress.sin_len=UInt8(sizeofValue(zeroAddress)

iOS:对 Alamofire 与 AFNetworking 的质疑

我正在开发一个新的通用应用程序(最低iOS7)并且我想使用Swift(这是我使用这种新语言的第二个应用程序)。在这个应用程序中我需要AFNetworking框架,但我对与新版本Alamofire的兼容性有一些疑问。我知道Alamofire和iOS7之间存在一些问题。所以你有什么建议?在此项目中使用Alamofire还是继续使用AFNetworking? 最佳答案 你可以只在你的项目中获取Alamofire.swift文件,而不是拖拽整个Alamofire项目。来自AlamofireGithubpage:SourceFileForap

ios - 要发布或放置的 Alamofire 原始 json 字符串

我如何使用Alamofire从put或post方法发送原始json字符串?我找不到任何例子。letparams=Mapper().toJSONString(results)//jsonstringwitharrayofobjectsAlamofire.request(.PUT,Config().apiGroup,parameters:params)获取错误:Cannotconvertvalueoftype'String?'toexpectedargumenttype'[String:AnyObject]?' 最佳答案 Alamofi

ios - 结合 Alamofire 和 RxSwift

我有这个Alamofire的自定义实现:protocolHTTPProtocol:class{typealiasRequestTypetypealiasRespondTypefuncdoRequest(requestData:RequestType)->SelffunccompletionHandler(block:(Result)->Void)->Self}//exampleofarequest:locationInfo//Makearequest.doRequest(HTTPLocationInfo.RequestType(coordinate:$0))//Callbackwhen

ios - 如何在 Alamofire 中设置 requestSerializer

我目前正在使用swift进行一个项目。我将Alamofire用于RESTAPI但要让它工作,我需要在requestSerializer中传递一个参数在AFNETWORKINGAFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManagermanager];manager.requestSerializer=[AFJSONRequestSerializerserializer];但是我找不到Alamofire的任何内容。我是swift的新手,请帮助我。 最佳答案

ios - 如何在 ObjectMapper 中映射 JSON 字典?

我有如下所示的json数据:{"balance":{"pointsEarned":3,"pointsAvailable":3,"pointsOnHold":0,"pointsConsumed":0,"nextReward":6}}我正在尝试映射“平衡”以便获得其他值:classAccountBalance:Mappable{varbalance:Dictionary?varpointsAvailable:Int?requiredinit?(_map:Map){}funcmapping(map:Map){balance根据objectMappergithubpage它是这样做的:Obje

ios - 在 Swift 中将 cUrl 命令转换为 HTTP 请求

我正在构建一个检查域可用性的应用程序。现在,我正在使用goDaddyAPI;根据goDaddy的说法,检查URL可用性的方法是通过以下cURL命令:curl-XGET-H"Authorization:sso-key{API_KEY}:{API_SECRET}""https://api.godaddy.com/v1/domains/available?domain=example.guru"现在,我正在尝试将该cURL命令转换为Swift。我正在使用Alamofire;但是,当我发出请求时,出现如下错误:Credentialsmustbespecified我想知道如何解决这个问题。这是我