私は、Web サーバーからデータをダウンロードする iPhone アプリに取り組んでいます。connection:willCacheResponse:
メソッドが呼び出されないことを除いて、すべてが正常に機能しています。しかし、他の人は、、、、connection:didReceiveResponse:
すべてconnection:didReceiveData:
正常connection:didFailWithError:
にconnectionDidFinishLoading:
動作しています。次のように接続しました。
- (void)makeConnection
{
NSURL *url = [NSURL URLWithString:@"http://www.abc.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
[request setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"%@", string];
[request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
NSCachedURLResponse *newCachedResponse = cachedResponse;
NSDictionary *newCachedResponseUserInfo = [NSDictionary dictionaryWithObject:[NSDate date] forKey:@"Cached Date"];
newCachedResponse = [[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response] data:[cachedResponse data] userInfo:newCachedResponseUserInfo storagePolicy:[cachedResponse storagePolicy]];
return newCachedResponse;
}
また、ポリシーを に変更しようとしましたNSURLRequestUseProtocolCachePolicy
が、何も役に立ちません。ブレイクポイントも入れてみた
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
しかし、何も起こりませんでした。何か不足していますか?前もって感謝します。