Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6347803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:17:34+00:00 2026-05-24T21:17:34+00:00

Our iPad app can show Documents and save them offline when needed. I’ve got

  • 0

Our iPad app can show Documents and save them offline when needed.
I’ve got a QLPreviewController subclass named DocumentViewController (named DVC from now on) for showing them.

Workflow of the app:
– The user clicks a name of a document and the DVC is pushed on to show the document.
– The DVC downloads the file offline and shows it when done.
(So the HTTP URL is downloaded, stored offline, and an offline URL is returned)

The weird thing is, is that only PDF files are working with the offline URL, and the rest crashes.. (it works with online links though)

I did some tests and when I put file:// before the offline link the app does not crash but the DVC is ging me some information about the file (like that it is a excel 97-2004 document).

So some info is transferred, but I can’t figure out what the problem is.

Here are some screenshots and after that some code.

enter image description here

code:
Note that Document is a model class with document properties like id, name, file type and url.

//DVC QLPreviewController dataSource method for returning url
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger)index
{
    [SaveHelper saveDocumentFileAndPropertyWithDocument:document];

    //[SaveHelper getDocumentFileWithDocument:document]; without file://
    //if I return document.documentUrl it is working with all files except iworks files)
    return [SaveHelper getDocumentFileAsPathWithDocument:document]; //with file://
}

//SaveHelper methods
+ (NSString *)documentFilePathWithDocument:(Document *)document
{
    return [[self documentFilePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%d.%@", DOCUMENT_FILE_PREFIX, document.documentId, document.documentType]];
}

+ (NSURL *)saveDocumentFileAndPropertyWithDocument:(Document *)document
{
    if([self saveDocumentPropertyWithDocument:document])
    {
        return [self saveDocumentFileWithDocument:document];
    }

    return nil;
}

+ (NSURL *)saveDocumentFileWithDocument:(Document *)document
{
    NSData *data = [NSData dataWithContentsOfURL:document.documentURL];

    NSString *fullPath = [self documentFilePathWithDocument:document];

   if([[NSKeyedArchiver archivedDataWithRootObject:data] writeToFile:fullPath atomically:YES])
   {
       return [NSURL fileURLWithPath:fullPath];
   }

    return nil;
}

+ (NSURL *)getDocumentFileWithDocument:(Document *)document
{
    return [NSURL fileURLWithPath:[self documentFilePathWithDocument:document]];
}

+ (NSURL *)getDocumentFileAsPathWithDocument:(Document *)document
{
    return [NSURL fileURLWithPath:[@"file://" stringByAppendingPathComponent:[[self getDocumentFileWithDocument:document] absoluteString]]];
}

If more code needed, just say.

EDIT:

When logging the URL passed trough the ‘getDocumentFileAsPathWithDocument’ method:

url: file:/var/mobile/Applications/xx-xx/Documents/documentFiles/file_20.pdf
url: file:/var/mobile/Applications/xx-xx/Documents/documentFiles/file_80.docx

Where the PDF file is working and the docx not

When I try to load an image(jpg) from local storage I get a black screen with this error message:

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.5 (8L1)/Symbols/System/Library/Frameworks/QuickLook.framework/DisplayBundles/Image.qldisplay/Image (file not found).
warning: No copy of Image.qldisplay/Image found locally, reading from memory on remote device.  This may slow down the debug session.

EDIT:

The webview does not work either with the local urls. PDF is fine but the office files gives an message “Unable to read Document, the file format is invalid”. The iWorks documents give the same error as the quicklook. I think its somewhere at the save and load of the format, I savve them as a NSDATA but after that there is no hint for the iPad to see if it is for example a word document (only the extension).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:17:35+00:00Added an answer on May 24, 2026 at 9:17 pm

    We finally found the solution!

    I was right that the problem was with saving the document.

    I needed to change the save method in:

    + (NSURL *)saveDocumentFileWithDocument:(Document *)document
    {
        NSData *data = [NSData dataWithContentsOfURL:document.documentURL options:NSDataReadingUncached error:nil];
    
        NSString *fullPath = [self documentFilePathWithDocument:document];
    
        if([[NSFileManager defaultManager] createFileAtPath:fullPath contents:data attributes:nil])
        {
            return [NSURL fileURLWithPath:fullPath];
        }
    //OLD CODE
    //   if([[NSKeyedArchiver archivedDataWithRootObject:data] writeToFile:fullPath atomically:YES])
    //   {
    //       return [NSURL fileURLWithPath:fullPath];
    //   }
    
        return nil;
    }
    

    SO saving it with the filemanager and not with a keyedarchiver.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our company is a subscription based service with an iPhone/iPad app that allows our
So I am working on an iPad app that needs to talk to our
We have created an iPhone app which our client wants to show on a
We need to test our asp.net website on an iPad, how can we do
In our native iPad app, we need a few customizations to be done to
In our iPad app, we would like to not allow the users to seek
In our iPad app, a video stream is playing in a player view. The
I am working on an image heavy iPad app. We implemented our own table
Our CEO wants our iPhone app's icons to look correct (ie not scaled) on
I'm trying to associate an SQLite3 database file with our app so that it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.