iOS 10中的sqlite3_prepare_v2 exc_bad_access

Nir*_*tel 6 sqlite xcode ios ios10

我在iOS项目中使用sqlite作为数据库.在iOS 9中,所有东西都运行得很好.现在我更新了新的Xcode.但是应用程序在'sqlite3_prepare_v2'上多次崩溃.

此外,我不是关闭数据库加班.并且只打开一次.我已经在下面的代码中添加了DB open在调试中的b'acs我得到了DB关闭.但仍然崩溃了.

紧急

谁能帮我 ?

提前致谢

Tom*_*żak 0

我认为问题出在第 2592 行。

在将 key 传递给 sqlite3_key(...) 时,不要将其视为字符串 不确定如何生成 key 但如果第一个字节设置为 '\0' 那么 strlen 返回 0 (如果您使用一些基于NSData 随机字节)

sqlite3_key定义:

SQLITE_API int SQLITE_STDCALL sqlite3_key(sqlite3 *db, const void *pKey, int nKey)
Run Code Online (Sandbox Code Playgroud)

它需要 nKey 字节,其中也允许“\0”

相反尝试:

 NSData *passBytes = [g_sqlite_key dataUsingEncoding:NSUTF8StringEncoding];
 int status = sqlite3_key(contactDB, passBytes.bytes, passBytes.length);
 if (status != SQLITE_OK) {
      // handle error and return
 }
 // continue...
Run Code Online (Sandbox Code Playgroud)