我想更新在线数据库。我意识到当我的网络连接到 Wi-Fi 时,按下刷新按钮时数据库会更新,但是当我的网络连接到 3g 时,数据库可能会或可能不会更新。如果它得到更新,即使我按下刷新按钮也需要很长时间。我认为缓存有问题,但我不确定如何将缓存放入我的代码中。这是我的代码:
- (void)downloadAtURLString:(NSString *)urlString
{
NSMutableData *data = [[NSMutableData alloc] init];
self.activeDownload = data;
[data release];
// encode the urlString with percent escapes
NSString *urlStr = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlStr];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
self.urlConnection = conn;
[conn release], [request release], [url release];
}
我尝试使用此代码:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
我收到警告.. cachePolicy 是否正确?