How to open sqlite database when app runs in background in ios

依然范特西╮ 提交于 2020-02-03 05:49:33

问题


My application captures location data in background and saves in sqlite database. It works well when Device is not locked, but when device is locked I am not able to access sqlite database. It always gives me error code as SQLITE_AUTH(error code:23). I have tried below options:

  1. Disable the Data Protection from Capabilities.(Does not work)
  2. As per Failed to create SQLite3 database with file protection in iOS, I tried the below code :

sqlite3_open_v2([dbPath UTF8String], &myDatabase, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_FILEPROTECTION_COMPLETE, NULL)

But still its not working.

Could you please help me, How to access the sqlite database in background.


回答1:


You need to enable Data Protection from your app from iTunesconnect.

1. Enable data protection for your app. For example,

2. Add below file protection key and value into your plist or entitlement file,

<key>com.apple.developer.default-data-protection</key>
<string> NSFileProtectionCompleteUntilFirstUserAuthentication</string>

The type must match to your capability set from itunes server.

3. Rebuild and test if the issue is resolved


File Data Protection In addition to the hardware encryption features built into iOS devices, Apple uses a technology called Data Protection to further protect data stored in flash memory on the device. Data Protection allows the device to respond to common events such as incoming phone calls, but also enables a high level of encryption for user data. Key system apps, such as Messages, Mail, Calendar, Contacts, Photos, and Health data values use Data Protection by default, and third-party apps installed on iOS 7 or later receive this protection automatically. Data Protection is implemented by constructing and managing a hierarchy of keys, and builds on the hardware encryption technologies built into each iOS device. Data Protection is controlled on a per-file basis by assigning each file to a class; accessibility is determined by whether the class keys have been unlocked. With the advent of the Apple File System (APFS), the file system is now able to further sub-divide the keys into a per-extent basis (portions of a file can have different keys). Find detail here in section File Data Protection.



来源:https://stackoverflow.com/questions/26364773/how-to-open-sqlite-database-when-app-runs-in-background-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!