Automatically save PDF annotations on iOS
When the isAutosaveEnabled
configuration property is true
, PDFView
and PDFViewController
will save “dirty” (changed/created/deleted) annotations on several occasions:
-
When the view disappears (in
viewDidDisappear(_:)
/onDisappear(perform:)
, unless Nutrient is presenting a fullscreen view on top of thePDFViewController
). -
When
saveAfterToolbarHiding
of theAnnotationToolbar
is enabled. -
When the app is moved into the background (
UIApplicationDidEnterBackgroundNotification
,UIApplicationWillTerminateNotification
). -
When
UIActivityViewController
asks for document data or a document 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, 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 a document. It’s not recommend to call this on a timer, because it can interrupt the creation of annotations if the user is drawing when the save occurs.