AFNetworking 4.0 pod install failed

The error is as follows:

//<<<<<<<<<<

Analyzing dependencies

[!] CocoaPods could not find compatible versions for pod "AFNetworking":

  In Podfile:

    AFNetworking (~> 4.0)

 

Specs satisfying the `AFNetworking (~> 4.0)` dependency were found, but they required a higher minimum deployment target.

 

[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

//<<<<<<<<<<

 

//Solution

Just change platform :ios, '8.0' in podfile to '9.0'.

Then the 4.0 post method has changed. Just replace the old post method with the new method.                             

There are more parameters in the post: headers:(NSDictionary <NSString *, NSString *> *)headers

 

//详情参考这个文章 https://www.jianshu.com/p/e8b21b3d690d
// 所有的请求方法都会进入这个方法 --- 返回一个请求任务
- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
                                       URLString:(NSString *)URLString
                                      parameters:(id)parameters
                                         headers:(NSDictionary <NSString *, NSString *> *)headers
                                  uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress
                                downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgress
                                         success:(void (^)(NSURLSessionDataTask *, id))success
                                         failure:(void (^)(NSURLSessionDataTask *, NSError *))failure
{
    NSError *serializationError = nil;
    
    // 对请求报文首部进行参数拼接完成之后的一个请求
    NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
    
    // 如果参数 headers 有值 那么就在对请求头进行设置
    for (NSString *headerField in headers.keyEnumerator) {
        [request addValue:headers[headerField] forHTTPHeaderField:headerField];
    }
    
    // 如果发生错误,异步返回错误, self.completionQueue 默认队列是NULL,会使用主队列,这个参数的意义是提供给外界自行定义,在什么队列中返回错误信息.
    if (serializationError) {
        if (failure) {
            dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
                failure(nil, serializationError);
            });
        }

        return nil;
    }

    // 根据请求返回一个任务
    __block NSURLSessionDataTask *dataTask = nil;
    
    // 基类调用父类封装的方法,获取一个请求任务.
    dataTask = [self dataTaskWithRequest:request
                          uploadProgress:uploadProgress
                        downloadProgress:downloadProgress
                       completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
        if (error) {
            // 请求失败
            if (failure) {
                failure(dataTask, error);
            }
        } else {
            // 请求成功
            if (success) {
                success(dataTask, responseObject);
            }
        }
    }];

    return dataTask;
}

 

Guess you like

Origin blog.csdn.net/ximiaoweilai/article/details/106427838