vfr/Reader — pull request #54 by liamnichols (2014-09-01 12:37:03+00:00)
Title: Fixed crash in iOS 8.

In iOS 8, the file system layout of app containers has changed on disk. Because of this change, the main .app bundle and the Documents/Library directories are stored in different places on the disk.

i.e:
Application Directory: `/private/var/mobile/Containers/Bundle/Application/E49D4518-5F07-425A-B743-03386C4644AF/Reader.app`
Documents Directory: `/var/mobile/Containers/Data/Application/98A0FF1A-F97E-4A6E-B10E-B58E5DCFA72B/Documents`

vfrReader creates a relativePath to store when archiving the `ReaderDocument` (to handle cases where the user may restore from a backup or use iCloud etc). This was fine in previous versions of iOS because it removes the applicationPath from the filePath of the supplied pdf.

However, in iOS 8. If i was loading a document from my main bundle (this can be reproduced in the demo app), the document would try to calculate its relativeURL from the `NSDocumentDirectory` minus the lastPathComponents.

If you use the two paths from above and try to do that, It is trying to remove `/var/mobile/Containers/Data/Application/98A0FF1A-F97E-4A6E-B10E-B58E5DCFA72B/` from `/private/var/mobile/Containers/Bundle/Application/E49D4518-5F07-425A-B743-03386C4644AF/Reader.app/Reader.pdf`

This obviously doesn't work as the range.length was NSNotFound causing the application to crash.

To fix the issue, I have modified the code to remove the `_fileName` ivar (so it is no longer archived) and to use a new `_filePath` ivar instead.
Because `unarchiveFromFileName:password:` supported being able to only pass in the lastPathComponent (i.e Reader.pdf). I have had to depreciate this method and I have replaced it with `unarchiveFromFilePath:password:`.

The application will still compile fine, but anybody trying to use the old method will have an assertion raised telling them to use the new method. You must pass the absolute filePath into this new method as it will also update the `_filePath` ivar on the document once it has been unarchived.

Let me know if you have any more questions.
Liam