pau*_*991 0 xml iphone google-reader file objective-c
我有这种方法从谷歌阅读器获取xml文件与feed阅读器的竞争.我想在本地保存数据(我确定数据是一个xml文件)我该怎么办?我可以存储本地数据以便以后读取它而无需连接互联网?我能怎么做?谢谢
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
{
NSLog(@"------------------------------- connectionDidReceiveResponse");
expectedResponseLength = [NSNumber numberWithFloat:[aResponse expectedContentLength]];
URLresponse = aResponse;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"------------------------------- connectionDidReceiveData: %@", data);
//float l = [responseData length];
//[delegate GoogleReaderRequestReceiveBytes:l onTotal:[expectedResponseLength floatValue]];
//TESTING
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"the data %@",string);
[self.responseData appendData:data];
}
Run Code Online (Sandbox Code Playgroud)
编辑**
我使用这个代码但是不起作用
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
{
NSLog(@"------------------------------- connectionDidReceiveResponse");
expectedResponseLength = [NSNumber numberWithFloat:[aResponse expectedContentLength]];
URLresponse = aResponse;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"------------------------------- connectionDidReceiveData: %@", data);
//float l = [responseData length];
//[delegate GoogleReaderRequestReceiveBytes:l onTotal:[expectedResponseLength floatValue]];
//TESTING
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"the data %@",string);
NSString *path=@"Library/News";
[data writeToFile:path atomically:YES];
[self.responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;
{
NSLog(@"------------------------------- connectionDidSendBodyData: %d", totalBytesWritten);
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)theError
{
NSLog(@"------------------------------- connectionDidFailWithError: %@", [theError localizedDescription]);
self.responseData = nil;
NSString *path=@"Library/News";
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
[self.responseData appendData:data];
[delegate GoogleReaderRequestDidFailWithError:theError];
}
Run Code Online (Sandbox Code Playgroud)
您可以使用writeToFile:atomically:方法来存储NSData对象.
样品:
[data writeToFile:path atomically:YES];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
804 次 |
| 最近记录: |