我设置了以下代码以将文件保存到文档目录:
NSLog(@"Saving File...");
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reddexuk.com/logo.png"]];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"logo.png"];
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(@"Error: %@", error);
}];
[operation start];
但是,我希望在成功保存后将每个文件添加到 UITableView。当点击 UITableView 中的文件时,我希望 UIWebView 导航到该文件(全部脱机)。
另外-我怎样才能获得文件名和结尾,例如“logo.png”而不是http://www.reddexuk.com/logo.png?
我怎样才能做到这一点?