小编kor*_*gx9的帖子

Alamofire 3自定义编码到Alamofire 4自定义编码

我有使用customParameterEncoding在Alamofire 3中编写方法.这个自定义编码只是在queryString中替换"[] ="和"="并返回它.

Alamofire.request(.GET, SearchURL, parameters: params, encoding: customEncoding, headers: headers).validate().responseJSON {
            response in
            switch response.result {
            case .success:
                print("success")
                break
            case .failure(let error):
                print("Error: " + error.localizedDescription)
                break
            }
        }
Run Code Online (Sandbox Code Playgroud)

和自定义编码参数

let customEncoding =  ParameterEncoding.Custom { requestConvertible, parameters in
    let (mutableRequest, error) = ParameterEncoding.URL.encode(requestConvertible, parameters: parameters)
    mutableRequest.URL = NSURL(string: mutableRequest.URLString.stringByReplacingOccurrencesOfString("%5B%5D=", withString: "="))
    return (mutableRequest, error)
}
Run Code Online (Sandbox Code Playgroud)

如何将customEncoding转换为Alamofire 4版本?

swift alamofire swift3

5
推荐指数
2
解决办法
3112
查看次数

Mapbox批注图像居中

我开始在项目中使用MapBox。当我添加带有自定义图像的注释时,它居中不正确。它似乎比原始引脚低一些。是否可以更改注释图像的中心点?

应该如何:

在此处输入图片说明

现在的状况:

在此处输入图片说明

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id <MGLAnnotation>)annotation {
    MGLAnnotationImage *annotationImage = [mapView dequeueReusableAnnotationImageWithIdentifier:@"driverPinId"];

    if (!annotationImage) {
        UIImage *image = [UIImage imageNamed:@"DriverPin"];
        annotationImageWithImage:image reuseIdentifier:@"driverPinId"];
    }

    return annotationImage;
}
Run Code Online (Sandbox Code Playgroud)

objective-c ios mapbox

4
推荐指数
1
解决办法
846
查看次数

Alamofire EmptyResponseCodes 不起作用

端点以代码 201 和空响应正文进行响应。查看 Alamofire 文档,只有 204 和 205 响应正文可以为空。有一个解决方案,我们可以指定结果为空的状态代码。添加了一组

emptyResponseCodes: [200, 201, 202, 203, 204, 205]

发送请求后,我仍然收到错误!= nil 我在这里做错了什么?

responseDecodable(of: TResult.self,
                  decoder: self.jsonDecoder,
                  emptyResponseCodes: [200, 201, 202, 203, 204, 205],
                  completionHandler: { (response: DataResponse<TResult, AFError>) in
                                    
                                    if let error = response.error {
                                        taskCompletionSource.set(error: error)
                                    } else if let result = response.value {
                                        taskCompletionSource.set(result: result)
                                    } else {
                                        taskCompletionSource.set(result: EmptyCodable())
                                    }
Run Code Online (Sandbox Code Playgroud)

ios swift alamofire alamofire5

3
推荐指数
1
解决办法
1229
查看次数

标签 统计

alamofire ×2

ios ×2

swift ×2

alamofire5 ×1

mapbox ×1

objective-c ×1

swift3 ×1