From 278e4190dbb228daa3a641d97d1ceb3ac9d49880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 15 Jun 2019 04:55:53 +0200 Subject: [PATCH] Enhance SQLite error 10/23 FAQ with sample code --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index d9d4f0f69..87a33dc73 100644 --- a/README.md +++ b/README.md @@ -8926,6 +8926,17 @@ Those errors may be the sign that SQLite can't access the database due to [data When your application should be able to run in the background on a locked device, it has to catch this error, and, for example, wait for [UIApplicationDelegate.applicationProtectedDataDidBecomeAvailable(_:)](https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623044-applicationprotecteddatadidbecom) or [UIApplicationProtectedDataDidBecomeAvailable](https://developer.apple.com/reference/uikit/uiapplicationprotecteddatadidbecomeavailable) notification and retry the failed database operation. +```swift +do { + try ... +} catch let error as DatabaseError where + error.resultCode == .SQLITE_IOERR || + error.resultCode == .SQLITE_AUTH +{ + // Handle possible data protection error +} +``` + This error can also be prevented altogether by using a more relaxed [file protection](https://developer.apple.com/reference/foundation/filemanager/1653059-file_protection_values).