hello everybody
,
I'm trying to download a pdf via url into my iPad cache file system and retrieve it, to show it in an uiwebview. i want to use asihttp but also choose alternatives as long as it works
i have 2 buttons in a scrollview: one to download and the second to display the pdf. I'm a beginner in obj c. so i need a bit help:
download function:
the activatey indicator is moving, but i can't see a file in my cache folder on simulator. do i miss something?
the display method:
when i click on the display button, nothing happens.
can somebody help me? have searched a lot on stack overflow but haunt found a solution yet.
I'm trying to download a pdf via url into my iPad cache file system and retrieve it, to show it in an uiwebview. i want to use asihttp but also choose alternatives as long as it works
download function:
Code:
NSURL *url = [NSURL URLWithString:@"urlForPDF"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your saved pdf location
NSString *pdfLocation = [documentDirectory stringByAppendingPathComponent:@"data.pdf"];
NSString *cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your temp pdf location
NSString *tempPdfLocation = [cachesDirectory stringByAppendingPathComponent:@"data.pdf"];
[request setTemporaryFileDownloadPath:tempPdfLocation];
[request setDownloadDestinationPath:pdfLocation];
[request startAsynchronous];
}
the activatey indicator is moving, but i can't see a file in my cache folder on simulator. do i miss something?
the display method:
Code:
- (IBAction)display:(id)sender {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
// init and create the UIWebView
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view delegates for the web view to be itself
[webView setDelegate:self];
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *pdfLocation = [documentDirectory stringByAppendingPathComponent:@"data.pdf"];
// Now tell your UIWebView to load that file
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:pdfLocation]]];
}
when i click on the display button, nothing happens.
can somebody help me? have searched a lot on stack overflow but haunt found a solution yet.