如何在AFNetworking iOS中禁用请求缓存?

前端之家收集整理的这篇文章主要介绍了如何在AFNetworking iOS中禁用请求缓存?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我注意到在我的iOS应用程序中有一个名为“cache.db”的文件,其中包含所有请求的URL,例如“http:/ / mywebsite.com/api/find.PHP?id=DEVICE_ID\u0026amp;secret=MY_SECRET”.

我正在使用AFNetworking来处理所有的http和https请求,我确实认为我没有为它设置任何缓存策略.如何删除或停止应用程序缓存请求的网址?我不希望我的用户(那些有root用户访问他们的手机/越狱设备的用户)看到这些网址.

同时,这是我的获取请求的示例

-(void){

    // Obtain Manager
    AFHTTPRequestOperationManager *manager = [self getHTTPRequestOperationManager];
    [manager GET:_path parameters:[self getRequestParams] success:[self getOperationSuccessBlock]
         failure:[self getOperationFailureBlock]];
}

- (AFHTTPRequestOperationManager *)getHTTPRequestOperationManager {
    self.operationManager = [APlacesProviderRequest manager:_basePath];
    return self.operationManager;
}

解决方法

AFNetworking github site开始:

Unlike NSURLConnection objects,which each share application-wide
settings for session management,cache policies,cookie storage,and
URL protocols,NSURLSession objects can configure these all
individually. Once a session is initialized with a particular
configuration,it can dispatch tasks to fetch data,and upload or
download files.

所以我想你可能会尝试使用该属性(我没有设备,所以我无法检查是否有效).

无论如何你可以尝试:[[NSURLCache sharedURLCache] removeAllCachedResponses];

猜你在找的Xcode相关文章