Auto Save PDF Annotations on iOS
PSPDFKit will save “dirty” (changed/created/deleted) annotations on several occasions.
-
When the view disappears (in
viewDidDisappear(_:)
/onDisappear(perform:)
, unless PSPDFKit is presenting a controller on top ofviewController
). -
When
saveAfterToolbarHiding
of theAnnotationToolbar
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 using
SignatureViewController
. -
When long-term validation is added to a form element.
-
When the selected tab of
PDFTabbedViewController
is changed.
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:reason:)
method on PDFViewController
. Use this only when you really understand what you’re 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.