ファイルをドキュメントディレクトリに保存するために、次のコードを設定しました。
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でそのファイルに移動します(すべてオフライン)。
また、 http://www.reddexuk.com/logo.pngの代わりに「logo.png」などのファイル名と末尾を取得するにはどうすればよいですか?
これどうやってするの?