Suppressing File Coordination Alerts

By default, PSPDFKit uses File Coordination to detect when the 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 are certain that the local changes cannot be worth preserving, you can suppress this alert by overriding PDFViewController’s implementation of the ConflictResolutionManagerDelegate method func resolutionManager(_:, shouldPerformAutomaticResolutionForFor:, dataProvider:, conflictType:, resolution:):

Copy
1
2
3
4
5
6
7
8
9
10
11
    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
    }
Copy
1
2
3
4
5
6
7
8
9
10
11
12
- (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;
    }
}

⚠️ Warning️: Please understand that this approach will discard user edits without further notice. Please also understand that 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.