Suppressing File Coordination Alerts

By default, PSPDFKit uses file coordination to detect when a file displayed by PDFViewController changes due to external file system events. If there are unsaved changes in the document, the user will be prompted to decide between the version on disk and the version currently displayed via an alert.

When you’re certain that the local changes aren’t worth preserving, you can suppress this alert by overriding PDFViewController’s implementation of the ConflictResolutionManagerDelegate method, func resolutionManager(_:, shouldPerformAutomaticResolutionForFor:, dataProvider:, conflictType:, resolution:):

override optional func resolutionManager(_ manager: ConflictResolutionManager, shouldPerformAutomaticResolutionForFor document: Document, dataProvider: CoordinatedFileDataProviding, conflictType type: FileConflictType, resolution: UnsafeMutablePointer<FileConflictResolution>) -> Bool {
        switch type {
        case .deletion:
            // Unconditionally close the document — EVEN WHEN THERE ARE UNSAVED CHANGES!
            resolution.pointee = .close
        case .modification:
            // Unconditionally reload the document from disk — EVEN WHEN THERE ARE UNSAVED CHANGES!
            resolution.pointee = .reload
        }
        return true
    }
- (BOOL)resolutionManager:(PSPDFConflictResolutionManager *)manager shouldPerformAutomaticResolutionForForDocument:(PSPDFDocument *)document dataProvider:(id<PSPDFCoordinatedFileDataProviding>)dataProvider conflictType:(PSPDFFileConflictType)type resolution:(inout PSPDFFileConflictResolution *)resolution {
    switch (conflictType) {
        case PSPDFFileConflictTypeDeletion:
            // Unconditionally close the document — EVEN WHEN THERE ARE UNSAVED CHANGES!
            *resolution = PSPDFFileConflictResolutionClose;
            return YES;
        case PSPDFFileConflictTypeModification:
            // Unconditionally reload the document from disk — EVEN WHEN THERE ARE UNSAVED CHANGES!
            *resolution = PSPDFFileConflictResolutionReload;
            return YES;
    }
}
Information

This approach will discard user edits without further notice. Additionally, attempting to preserve the current changes as Instant document JSON, reloading the document from disk, and then applying that Instant document JSON to the reloaded document is, generally unsafe.