AFNetworking 4.0 pod install失败

报错如下:

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

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.

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

//解决方法

把podfile里的  platform :ios, '8.0' 改成’9.0‘就可以了。

然后4.0的post方法有改变。用新方法替换掉旧的post方法就好了。                             

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;
}

猜你喜欢

转载自blog.csdn.net/ximiaoweilai/article/details/106427838