Ich verwende schon seit längerer Zeit den vfr/reader Example.
Ich habe das Internet schon nach diversen Examples durchforscht und einiges gefunden.
Hier habe ich habe 2 hilfreiche Codes gefunden wobei auf eine PDF-Datei zugegriffen wird und ins Verzeichnis am iDevice gespeichert wird
1. Die PDF-Datei lässt sich nach dem Download nicht öffnen -> Absturz (Ich vermute, dass es beim vfr/Reader liegt und der path falsch ist)
2. Welcher von den beiden Codes ist "besser"
Alles anzeigen
Alles anzeigen
Danke im Voraus!
Ich habe das Internet schon nach diversen Examples durchforscht und einiges gefunden.
Hier habe ich habe 2 hilfreiche Codes gefunden wobei auf eine PDF-Datei zugegriffen wird und ins Verzeichnis am iDevice gespeichert wird
1. Die PDF-Datei lässt sich nach dem Download nicht öffnen -> Absturz (Ich vermute, dass es beim vfr/Reader liegt und der path falsch ist)
2. Welcher von den beiden Codes ist "besser"
C-Quellcode
- -(IBAction) downloadButtonPressed:(id)sender;{
- //download the file in a seperate thread.
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSLog(@"Downloading Started");
- NSString *urlToDownload = @"http://www.webseite.eu/test.pdf";
- NSURL *url = [NSURL URLWithString:urlToDownload];
- NSData *urlData = [NSData dataWithContentsOfURL:url];
- if ( urlData )
- {
- //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- //NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *documentsDirectory = [[NSString alloc] initWithString:[[NSBundle mainBundle] resourcePath]];
- NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"test.pdf"];
- //saving is done on main thread
- dispatch_async(dispatch_get_main_queue(), ^{
- [urlData writeToFile:filePath atomically:YES];
- NSLog(@"File Saved !");
- });
- }
- });
- }
C-Quellcode
- // Get the PDF Data from the url in a NSData Object
- NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.webseite.eu/test.pdf"]];
- // Store the Data locally as PDF File
- NSString *resourceDocPath = [[NSString alloc] initWithString:[[[
- [NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]
- stringByAppendingPathComponent:@"Documents"]];
- NSString *filePath = [resourceDocPath
- stringByAppendingPathComponent:@"test.pdf"];
- [pdfData writeToFile:filePath atomically:YES];
Danke im Voraus!