I have a UIViewController
with an UIWebView
which displays a pdf file depending which row was clicked before in an UITableView
. Now I want
You can try this way:
1) Add a button to the View
containing UIWebView
2) At button press save the file shown in UIWebView
(note: in iOS 5 you must save data that can be easily recreated or downloaded to the caches directory)
- (IBAction)buttonPress:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
//You must check if this directory exist every time
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO)
{
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}
NSString *filePath = [cachePath stringByAppendingPathComponent:@"someName.pdf"]
//webView.request.URL contains current URL of UIWebView, don't forget to set outlet for it
NSData *pdfFile = [NSData dataWithContentsOfURL:webView.request.URL];
[pdfFile writeToFile:filePath atomically:YES];
}
3) On application start you need to check what files are stored (iOS can delete cache directory if there is not enough space on iPhone)