AFNetworking ElfSundae UIWebView-补丁

AFNetworking ElfSundae UIWebView-Patch

我更新了 AFNetworking Pod 以摆脱 UIWebView 作为 https://github.com/ElfSundae/AFNetworking/issues/1 建议。

但现在我收到了一些过时的警告: 'GET:parameters:progress:success:failure:' is deprecated.

在代码处: [manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { ....

我已经使用迁移指南仔细检查了代码 - 但我看不出有什么问题..

谢谢

马丁

提交 ded6a76 添加了 GET:parameters:headers:... 方法以支持每个 HTTP 请求设置 headers,并弃用了 GET:parameters:... 方法。

我的分支基于 AFNetworking 主分支上的最新提交,包括此提交。

没有 headers 参数的旧 GET 方法刚刚被弃用,您可以安全地使用它,或者迁移您的代码以使用传递 headers:nil 的新 GET 方法.或者您可以创建 AFHTTPSessionManager 的子类来禁用警告:

@interface MyHTTPSessionManager : AFHTTPSessionManager

// These three methods below have been marked as deprecated in AFNetworking,
// we override them here and remove DEPRECATED_ATTRIBUTE to silence the
// deprecated-warning.


- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
                            parameters:(nullable id)parameters
                               success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                               failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;

- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
                             parameters:(nullable id)parameters
                                success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                                failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;

- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
                             parameters:(nullable id)parameters
              constructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> formData))block
                                success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                                failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;

@end

@implementation MyHTTPSessionManager

- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
                            parameters:(nullable id)parameters
                               success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                               failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure
{

    return [self GET:URLString parameters:parameters progress:nil success:success failure:failure];
}

- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
                             parameters:(nullable id)parameters
                                success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                                failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure
{
    return [self POST:URLString parameters:parameters progress:nil success:success failure:failure];
}

- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
                             parameters:(nullable id)parameters
              constructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> formData))block
                                success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
                                failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure
{
    return [self POST:URLString parameters:parameters constructingBodyWithBlock:block progress:nil success:success failure:failure];
}

@end

代码来自 ESAPIClient