Enhance SQLite error 10/23 FAQ with sample code

This commit is contained in:
Gwendal Roué committed 2019-06-15 04:55:53 +02:00
1 parent d3fe40127c
commit 278e4190db
1 file changed
+11
+11
View File
@@ -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).