0
我正試圖下載並緩存iPhone文檔目錄中的數據。我希望能夠檢查文件是否存在,並使用本地數據填充我的UITableViewCell(如果存在),並在遠程加載數據(如果不存在)。如何確定某個名稱的文件是否存在於我的iOS文檔目錄中
這是我用來下載數據的代碼。
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"The Error Is: %@", error);
}];
NSFileManager有一個方法來查看文件是否存在於路徑中。 – rmaddy 2013-02-14 21:51:01