vfr/Reader - PDF Datei über externen Link downloaden und dann über den vfr/Reader öffnen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • vfr/Reader - PDF Datei über externen Link downloaden und dann über den vfr/Reader öffnen

    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"

    C-Quellcode

    1. -(IBAction) downloadButtonPressed:(id)sender;{
    2. //download the file in a seperate thread.
    3. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    4. NSLog(@"Downloading Started");
    5. NSString *urlToDownload = @"http://www.webseite.eu/test.pdf";
    6. NSURL *url = [NSURL URLWithString:urlToDownload];
    7. NSData *urlData = [NSData dataWithContentsOfURL:url];
    8. if ( urlData )
    9. {
    10. //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    11. //NSString *documentsDirectory = [paths objectAtIndex:0];
    12. NSString *documentsDirectory = [[NSString alloc] initWithString:[[NSBundle mainBundle] resourcePath]];
    13. NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"test.pdf"];
    14. //saving is done on main thread
    15. dispatch_async(dispatch_get_main_queue(), ^{
    16. [urlData writeToFile:filePath atomically:YES];
    17. NSLog(@"File Saved !");
    18. });
    19. }
    20. });
    21. }
    Alles anzeigen


    C-Quellcode

    1. // Get the PDF Data from the url in a NSData Object
    2. NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.webseite.eu/test.pdf"]];
    3. // Store the Data locally as PDF File
    4. NSString *resourceDocPath = [[NSString alloc] initWithString:[[[
    5. [NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]
    6. stringByAppendingPathComponent:@"Documents"]];
    7. NSString *filePath = [resourceDocPath
    8. stringByAppendingPathComponent:@"test.pdf"];
    9. [pdfData writeToFile:filePath atomically:YES];
    Alles anzeigen

    Danke im Voraus!