Search code examples
objective-cxcodeuiwebviewafnetworking

AFNetworking ElfSundae UIWebView-Patch


I have updated the AFNetworking Pod to get rid of the UIWebView as at https://github.com/ElfSundae/AFNetworking/issues/1 suggested.

But now I get some depreciated warnings: 'GET:parameters:progress:success:failure:' is deprecated.

At the code: [manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { ....

I have double checked the code with the migration-guide - but I can't see whats wrong..

Thank you

Martin


Solution

  • The commit ded6a76 added GET:parameters:headers:... method to support setting headers per HTTP request, and deprecated GET:parameters:... method.

    My fork is based on the latest commit on the master branch of AFNetworking, includes this commit.

    The old GET method without headers parameter is just deprecated, you can use it safely, or migrate your code to use the new GET method passing headers:nil. Or you may create a subclass of AFHTTPSessionManager to disable the warnings:

    @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
    

    code from ESAPIClient