Failed to display UIWebView to display docx/xlsx file with SFUZipEndOfCentralDirectoryError error with custom URL - iphone

We are writing some program to display documents on iOS. I think that there are a lot of confusion on the web about what type of documents which iOS UIWebView could display. Generally people refer to Technical Q&A QA1630 Using UIWebView to display select document types to see that all the MS office 07+ files (such as docx, xlsx, pptx) could not be displayed, however actually that is not what we see from testing. Actually we are able to display docx/xlsx/pptx document at UIWebView either loading from a remote URL, local file or in memory (loadData, here the baseURL can not be nil on simulator, see this link). Of course We are testing on latest version of iOS on iPhone simulator, it might be that the support was not at older iOS. At this point, We don't know that yet. If you know, please let me know.
However right now, We have one issue to display document at UIWebView by using custom URL for security reason. I did the custom URL by following the code here: protecting iOS resource. We could display xls, doc, ppt, pdf file, but not docx/xlsx/pptx, We got some error like this:
EXCEPTION SFUZipEndOfCentralDirectoryError: Could not find the end of central directory record
We tried to debug and could not figure what's to do here. Do you see similar error here? Could anyone shed some lights on this? Thanks very much.

It looks like the document you're trying to open might be corrupt. docx, xlsx, and pptx files are actually zip files containing a bunch of XML documents and other data. Check if you are able to uncompress the file on your computer by renaming it to .zip and then unzipping.

Related

Swift PDFView and URLs that end in "/pdf" instead of ".pdf"

I have code that loads a pdf file into the PDFView that Apple provides in Swift. It works great, but the problem comes when trying to view pdf files where the URL is not formatted correctly.
For example, if I provide a URL for the PDFView that looks like http://www.example.com/files/myfile.pdf the PDFView works just fine. However, when I provide it with a URL that looks like http://www.example.com/files/articles/article-432/pdf it no longer functions. Both URLs (in the code) point to perfectly valid pdf documents, but only the former actually loads into the PDFView.
EDIT So after setting the environment variable CG_PDF_VERBOSE in Xcode, the console returned failed to find PDF header: '%PDF' not found. Not really sure what this means, though I suspect it probably means that there is some sort of redirect to the actual file, so I can't get the file directly.
Sorry that I can't share the actual URLs, but its just because they are company specific and I'm not allowed to distribute them.
Thanks in advance for any help!

File uploads from Google Drive using Safari on iPhone result in 0 byte files

We have a form on our website where you can apply for jobs, and it has a file upload field so you can upload your resumé. It allows .doc, .docx and .pdf files.
Sometimes the form submits successfully but the file is 0 bytes on our server.
I was able to figure out that all the form submissions that result in a 0 byte file upload were from iPhones, and by filling out the form myself on my iPhone, discovered that if the resumé is stored on Google Drive, and then I upload it via the form, that's what results in the 0 byte file.
If it's stored on iCloud Drive, then it's fine. It's an appropriately sized file that opens properly in the right application (Acrobat or Word).
Anybody have any suggestions as to how I can remedy the situation, or where to even start? I have Googled it extensively, and can't find any other discussion of this particular weirdness. Apologies if this is the wrong place to post the question, and I would appreciate pointers to the right place if necessary.
I'm afraid this is an iOS bug, still present in version 12.3.1 and dating back to at least 2016, we have the same issue. I think the only options that exist are: prevent the form being used on iOS, detect 0 byte files in server-side validation and ask the user to resubmit (not great but at least you're not losing data), or move to an AJAX-style file upload. See also this related issue.

Where to store a preview of a UIDocument?

I'm working on UIDocument application and I'd like to show the user a preview of the document before he opens it. I can render that preview into an image when the document get's closed. But where should I save that image? In an other file? or is there a designated way to do this?
Right now I'm developing it without iCloud support. But I want to have a solution that would work with iCloud too. The UIDocument is a UIManagedDocument. But saving the image into the database would make it kind a pointless. Because then I have to open the document before I can get the preview.
What do you recommend here? Where to put a preview for a UIManagedDocument?
You can store your documents in your ubiquity container's Documents directory and document preview files in the container's Data directory.
If preview file names will be based on the documents names you will be able to use metadata query result to get the document names and then resolve document preview urls.
This way you could download the document previews only but not the whole document.
I don't know about UIManagedDocuments, but in case of a UIDocument I would recommend using a NSFileWrapper as file format (where the document is actually a bundled folder) and save the preview within the document, as "Preview.jpg" (or .png) inside a folder labeled "QuickLook".
This way, you'll get the preview in Finder on the Mac as well (for free).
Of course this may or may not be an ideal solution (also depending on if your document is text-only). But it might be a good hint for working with previews for UIDocuments in general.
You should save an image under (app_directory)/Library/Caches. That way iCloud won't affect your app.

Reading pdf file in ipad application

In my Ipad application i need to read .pdf files. these pdf files are stored in my server. the size of the pdf files are nearly 20Mb. Normaly in ipad we can view the pdf using UIwebview, but it's not useful in this case. the reason is normaly in iPad the pdf files are downloaded and showed in UIWebview.. but in my case the size maters..so i need another solution to read pdf files.
my suggestion is take the pdf in a spitted fashion.means suppose ur pdf contains 1000 pages download first page and load on the webView and start download for the remaining pages in the background something like nsoperationquee .so you need to modify in the server side also if you like my suggestion.
You have pdf url that in server right? get the pdf files from the server and store it locally like DB. After that you can display the PDF files from the DB. This is the one time process.Then it not take much time for download.
Or you get the pdf images and display in the uiimageview its simple and easy. But one drawback is you can read the text but not do any action on that i.e., copy the text like that
Thanking you

Retrieving updated files from server to replace files on documents folder of an iPhone

Im new to iPhone programming and wanted to see how people have solved this problem:
Ive created my app which will ship with certain pLists and .png files in the main bundle. However, what I want to do is when the app starts up, Id like it to check my server to see if there are updated versions of the files in the documents folder available. If so Id like the app to download those files.
I was wondering if someone can point me to some resources on how to do this? Ive searched online but haven't come up with good hits.
Whats the google key-word for searching this topic anyways?
Thanks a lot
you can use NSUrlRequest to download the files, to move them to the correct place you can use NSFileManager, if you look at the apple docs for both these classes there should be sample code explaining how to copy/save a file from NSData, and also how to download it.
I don't have any example resources of how to do exactly this, though I would probably do something along the lines of onAppLoad checking to see if the content of the application that you want to keep updated is the most recent, and if not, download it.
As for keywords to search I would try something along the lines of "Automatic App Content Updating/Verification" and throw in "iOS/iPhone/iPad" or some similar combination.
I'll do some more poking around and shoot you a comment notification if I find anything worthwhile, and then edit my post with it.