From 3c0a6f0e29f2e57e6be6832147ae57825809fde0 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 30 Sep 2026 08:23:51 +0100 Subject: [PATCH] ios: exclude app data from backup (#7623) Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> --- apps/ios/Shared/AppDelegate.swift | 1 + apps/ios/SimpleXChat/FileUtils.swift | 12 ++++++++++++ apps/ios/spec/database.md | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/apps/ios/Shared/AppDelegate.swift b/apps/ios/Shared/AppDelegate.swift index 0a401f9bf3..8cc6d816b5 100644 --- a/apps/ios/Shared/AppDelegate.swift +++ b/apps/ios/Shared/AppDelegate.swift @@ -123,6 +123,7 @@ class AppDelegate: NSObject, UIApplicationDelegate { private func prepareForLaunch() { try? FileManager.default.createDirectory(at: getWallpaperDirectory(), withIntermediateDirectories: true) + excludeAppDataFromBackup() } static func keepScreenOn(_ on: Bool) { diff --git a/apps/ios/SimpleXChat/FileUtils.swift b/apps/ios/SimpleXChat/FileUtils.swift index a4d4e4ae0c..0c1852b09c 100644 --- a/apps/ios/SimpleXChat/FileUtils.swift +++ b/apps/ios/SimpleXChat/FileUtils.swift @@ -66,6 +66,18 @@ func getAppDirectory() -> URL { : getDocumentsDirectory() } +public func excludeAppDataFromBackup() { + var values = URLResourceValues() + values.isExcludedFromBackup = true + for var dir in [getGroupContainerDirectory(), getDocumentsDirectory()] { + do { + try dir.setResourceValues(values) + } catch { + logger.error("FileUtils.excludeAppDataFromBackup error: \(error.localizedDescription)") + } + } +} + // Spec: spec/database.md#DB_FILE_PREFIX let DB_FILE_PREFIX = "simplex_v1" diff --git a/apps/ios/spec/database.md b/apps/ios/spec/database.md index 9e5adfcb64..cb08abe2aa 100644 --- a/apps/ios/spec/database.md +++ b/apps/ios/spec/database.md @@ -74,6 +74,10 @@ See [`getDocumentsDirectory()`](../SimpleXChat/FileUtils.swift#L47) and [`getGro The container choice is stored in `dbContainerGroupDefault` (`GroupDefaults`). +### Backup Exclusion + +`isExcludedFromBackup` is set on both containers by [`excludeAppDataFromBackup()`](../SimpleXChat/FileUtils.swift#L69-L79), which is called from [`prepareForLaunch()`](../Shared/AppDelegate.swift#L124-L127) on each app launch. Files that the app, NSE and SE create or replace in these directories later are excluded as well. + --- ## 3. Haskell Store Modules