AFNetwoworking 网络请求时间设置

来源:互联网 发布:赚钱宝pro映射哪些端口 编辑:程序博客网 时间:2024/06/06 17:13

AFNetwoworking 网络请求时间设置

前言:

最近用了AFNetwoworking 网路请求框架。

如果大家想要认真学习请下载文档(中文+英文)双语:文档下载

我们可能会这样:调用AFHTTPRequestOperationManager 的GET 和 POST 方法时,网络请求时间60秒,就像我会觉得时间有点长,我想改为10 秒;

方法:

1、首先我们找到AFURLRequestSerialization.m文件

2、然后找到找到下面这个函数:

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method                                 URLString:(NSString *)URLString                                parameters:(id)parameters                                     error:(NSError *__autoreleasing *)error

3、将函数内的:

NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:url];

改为

NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];

(网络请求时间设置后面参数timeoutInterval 单位为秒)

0k;










1 0