1
私はUIWebViewからpngファイルを保存するためにいくつかのコードを使用しています。動作していません。「保存」ボタンを押すと何も起こりません。 「ファイルの保存...」とは別に、ログには何も表示されません。これは、すべてがInterface Builderで正しくリンクされていることをテストすることだけです。ファイルが保存されないのはなぜですか?
-(IBAction)saveFile
{
NSLog(@"Saving File...");
NSURL *requestedURL = [webView.request URL];
if([[requestedURL pathExtension] isEqualToString:@"png"])
{
NSData *fileData = [[NSData alloc] initWithContentsOfURL:requestedURL];
//Store the data locally
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath]
stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:[requestedURL lastPathComponent]];
NSError *error = nil;
[fileData writeToFile:filePath options:NSDataWritingFileProtectionComplete error:&error];
if(error != nil) {
// Failed to write the file
NSLog(@"Failed to write file: %@", [error description]);
} else {
UIAlertView *filenameAlert = [[UIAlertView alloc] initWithTitle:@"File saved" message:[NSString
stringWithFormat:@"The file %@ has been saved", [requestedURL lastPathComponent]] delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[filenameAlert show];
[filenameAlert release];
}
}
あなたは 'resourceDocPath'パスを正しく構築していないかもしれません。私は通常これを使用します: '#define _docs [NSHomeDirectory()stringByAppendingPathComponent:@" Documents "]' –
'AlertView'は表示されますか? – Nekto