Auto Save PDF Annotations on iOS

PSPDFKit will save “dirty” (changed/created/deleted) annotations on several occasions.

  • When the viewController is popped (in viewWillDisappear(_:), unless PSPDFKit is presenting a controller on top of viewController).

  • When the document on the PDFViewController is changed.

  • When saveAfterToolbarHiding of the AnnotationToolbar is enabled.

  • When the app is moved into the background (UIApplicationDidEnterBackgroundNotification, UIApplicationWillTerminateNotification).

  • When UIActivityViewController asks for a document data/URL to share.

  • When a document will be digitally signed.

Each time the document is saved, the pdfDocumentDidSave(_:) delegate method on PDFDocumentDelegate is called. If there were no new changes to save, the delegate won’t be called.

Saving can also be controlled on a per-document level by setting annotationSaveMode.

Customize Autosaving

To customize the autosaving behavior, you can override the handleAutosaveRequest(for document: Document, reason: PSPDFAutosaveReason) method on PSPDFViewController. Use this only when you really understand what you are doing, as there might be unintended side effects, such as sharing not working as expected.

Manual Saving

Saving can always be triggered from the main thread by calling save(options:) on the document.