Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude DB from backup/icloud (iOS) #103

Open
dusiema opened this issue Sep 5, 2023 · 2 comments
Open

Exclude DB from backup/icloud (iOS) #103

dusiema opened this issue Sep 5, 2023 · 2 comments

Comments

@dusiema
Copy link

dusiema commented Sep 5, 2023

I use sqldelight in a KMM app project. I store sensitive cached data, mostly in the form of base64 encoded images as strings.
It's only meant to be used as a cache when there is no network.

I want to avoid the underlying SQLite db from being included in an iOS backup or iCloud sync/backup.

Theres is a key that one can set for this: NSURLIsExcludedFromBackupKey.

How can I set this on the SQLite DB for the native iOS part of the app?

@dusiema
Copy link
Author

dusiema commented Sep 11, 2023

I ended up setting the attribute right after the NativeSqliteDriver is created by using this function:

    @OptIn(ExperimentalForeignApi::class)
    fun setExcludeFromBackup() {
        return memScoped {
            val databasePath = DatabaseFileContext.databasePath(databaseName, null)
            if (NSFileManager.defaultManager.fileExistsAtPath(databasePath)) {
                val errorRef = alloc<ObjCObjectVar<NSError?>>()
                Napier.i { "Excluding ${databasePath} from iCloud/Backup!" }
                val success = NSURL.fileURLWithPath(databasePath).setResourceValue(NSNumber(bool = true), NSURLIsExcludedFromBackupKey, errorRef.ptr)
                if (!success) {
                    Napier.i { "Excluding ${databasePath} from iCloud/Backup failed! Reason: ${errorRef.value}" }
                }
            }
        }
    }

I have yet to test if this does work at all by really doing a backup of a real iphone and check if the database file is not included. So be aware this is untested.

@dusiema
Copy link
Author

dusiema commented Sep 11, 2023

Side note: I pulled a backup from an iPhone but seemingly developer signed apps are not included in an iPhone backup anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant