1

我使用 AFNetworking 作为我的基本网络课程。当我在越狱手机上进行内存转储时,我可以很容易地在转储文件中以纯文本形式查看请求 url 或响应(如 json 对象)。我检查了xcode中的泄漏工具,并没有基于此的内存泄漏。我的应用在 url 或响应中有敏感数据(如用户名、电子邮件地址...),我想在连接完成后立即清除这些信息。

我尝试在应用程序中禁用 NSURLCache:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0
                                                        diskCapacity:0
                                                        diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];

我也试过:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

或者

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];

但这些都不起作用。有谁知道该怎么做?

4

1 回答 1

0

你试过这个吗?

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];

您还需要从服务器端脚本的标头响应中禁用缓存。如果它在 PHP 中:

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

Apple 非常尊重响应标头。

于 2015-06-05T00:14:06.517 回答