XCode9-beta:函数'sqlite3_key'的隐式声明

时间:2017-06-06 12:29:57

标签: ios sqlite xcode9-beta

我遇到EncryptedStore SQLCipher wrapper加密核心数据的问题 我为此添加了C标志:

Debug = -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE -DSQLCIPHER_CRYPTO_CC
Release = -DSQLITE_HAS_CODEC -DNDEBUG -DSQLITE_OS_UNIX=1 -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE -DSQLCIPHER_CRYPTO_CC

并将其用作:

func encryptedCoordinator() -> NSPersistentStoreCoordinator {
  var coordinator:NSPersistentStoreCoordinator?
  let ops:[String : Any] =    [NSMigratePersistentStoresAutomaticallyOption:(true),                                              NSInferMappingModelAutomaticallyOption:(true), EncryptedStorePassphraseKey:sqlCipherKey, EncryptedStoreDatabaseLocation:self.sqliteFileURL()]

  do {
      coordinator = try EncryptedStore.make(options: ops, managedObjectModel: self.managedObjectModel, error: ())
    }catch {
      fatalError("Error opening encrypted DB: \(error)")
    }
    return coordinator!
  }

它在XCode8中工作正常,但它在XCode9-beta中出错
错误行:

- (BOOL)changeDatabasePassphrase:(NSString *)passphrase error:(NSError *__autoreleasing*)error {
  BOOL result;
  int status;
  if ([passphrase length] > 0) {
    // Password provided, use it to key the DB
    const char *string = [passphrase UTF8String];
    status = sqlite3_rekey(database, string, (int)strlen(string));//ERROR line
    string = NULL;
    passphrase = nil;
  } else {
    // No password
    status = SQLITE_OK;
  }
  result = status == SQLITE_OK;
  if (result) {
    result = [self checkDatabaseStatusWithError:error];
  }
return result && (*error == nil);
}

函数在EncryptedStroe/sqlite3.h中声明为:

SQLITE_API int sqlite3_rekey(
sqlite3 *db,                   /* Database to be rekeyed */
  const void *pKey, int nKey     /* The new key */
);
SQLITE_API int sqlite3_rekey_v2(
  sqlite3 *db,                   /* Database to be rekeyed */
  const char *zDbName,           /* Name of the database */
  const void *pKey, int nKey     /* The new key */
);

2 个答案:

答案 0 :(得分:9)

我认为问题是导入的EncryptedStore.m文件: #import <sqlite3.h>

它使用&lt;&gt;因此导入系统sqlite库,但不包含这些功能。通过更改&lt;&gt;用&#34;&#34;一切都很好。

答案 1 :(得分:5)

找到另一个解决方案here

主要更改标题搜索路径 尝试从$(PROJECT_DIR)/sqlcipher/src更改它 到$(PROJECT_DIR)/sqlcipher
(即从路径中删除/src)。“对我来说是诀窍。