问题描述
背景:我一直在观看WWDC 2011 - 208保护iOS应用程序。他们提到如何使用称为NSFileProtection的文件加密来保护我们的数据。当我发现时,我希望手动方式(@ 37:00)不行。我尝试使用文件保护与图像,一切都很好。只有Sqlite我无法创建。
Background: I have been watching through WWDC 2011 - 208 Securing iOS application. They mention about how to secure our data with file encryption called NSFileProtection. While I discover the automatic method mentioned (@38:00) is bugged, I hope the manual way (@37:00) is not. I tried using file protection with images and all is well. Only Sqlite I cannot create.
问题:我尝试使用 sqlite3_open_v2创建SQLite3数据库(没有核心数据) / code>并将
SQLITE_OPEN_FILEPROTECTION_COMPLETE
作为第三个参数的标志。它不返回 SQLITE_OK
。
Problem: I try to create SQLite3 database (without core data) with
sqlite3_open_v2
and passing SQLITE_OPEN_FILEPROTECTION_COMPLETE
as the flag for the third argument. It does not return SQLITE_OK
.
代码
if (sqlite3_open_v2([databasePath UTF8String], &database, SQLITE_OPEN_FILEPROTECTION_COMPLETE, NULL) == SQLITE_OK){
//everything works
}else{
//failed
}
更新:
如borrrden所述,两者都导致以下错误代码:
SQLITE_MISUSE
(库使用不正确)
更新2:
borrrden的第二个评论是正确的,指出两个标志的需要。它的代码如下:
Update 2:borrrden's 2nd comment was correct to point out the need for both flags. It works following the code:
if (sqlite3_open_v2([databasePath UTF8String], &database, SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_FILEPROTECTION_COMPLETE, NULL) == SQLITE_OK)
推荐答案
Sqlite对于缺少在您的标志中指定的文件访问模式。它不知道是否应该打开它可写,或者是否创建它是否不存在。因此,添加以下两个标记以及您当前使用的两个标志:
Sqlite is not happy about the lack of a file access mode being specified in your flags. It doesn't know whether it should open it writable or not, or whether or not to create it if it does not exist. Therefore, add the following two flags along with the one you are currently using:
这表示sqlite应该打开可写数据库,如果不存在,则创建它。
This signals that sqlite should open a writable database, and create it if it does not exist.
这篇关于在iOS中无法创建具有文件保护功能的SQLite3数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!