Я использую некоторый код для сохранения файла png из UIWebView.Он не работает и ничего не происходит при нажатии кнопки «Сохранить».Ничего не появляется в журнале, кроме «Сохранение файла ...», которое просто для проверки того, что все правильно связано в Интерфейсном Разработчике (что это такое).
Вот код, который я использую:
-(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];
}
}