【发布时间】:2017-02-13 13:11:18
【问题描述】:
This here i have shared to show that i have Sqlite file present in copy bundle resources : 我在iOS 应用程序中使用 Sqlitecipher 在Simulator(离线)中运行我的应用程序时,它成功显示所有数据,并且每个查询都可以正常工作,例如 (update,delete,insert) 但在设备上测试我的应用程序时,它没有显示任何内容。按照我尝试的方式:
- 已将
Sqlite文件保存在包中 - 将
Sqlite文件从包复制到DocumentDirectory - 从
Simulator删除应用程序并重置我的Simulator,但我仍然面临同样的问题。请提出解决方案(它是一个 Salesforce 原生应用程序)
这是从包中获取文件到Document DirectoryAppdelegate中的代码:`
func copyFile()
{
var documents: NSString
documents = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
let bundlePath = NSBundle.mainBundle().pathForResource("LeadWork1", ofType: "sqlite")
print(bundlePath, "\n") //prints the correct path
let destPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first!
let fileManager = NSFileManager.defaultManager()
let fullDestPath = NSURL(fileURLWithPath: destPath).URLByAppendingPathComponent("LeadWork1.sqlite")
let fullDestPathString = fullDestPath.path
print(fullDestPathString)
print(fileManager.fileExistsAtPath(bundlePath!)) // prints true
if fileManager.fileExistsAtPath(bundlePath!) == true
{
print("File Exist")
}
else
{
do{
try fileManager.copyItemAtPath(bundlePath!, toPath: [enter image description here][1]fullDestPathString!)
}catch{
print("\n")
print(error)
}
}
let error = sqlite3_open(fullDestPathString!, &database)
if error != SQLITE_OK
{
print("Error while opening");
}
else
{
// print(fileForCopy)
print(destPath)
print("already open");
}
}`
我们将不胜感激!
【问题讨论】:
-
您需要分享一些代码才能在这里得到答案?
-
你在哪里实际使用密码,并解密数据库?
-
@max_ 我已按照此 Url (zetetic.net/sqlcipher/ios-tutorial) 中提到的步骤将 sqlite 密码集成到我的项目中。构建成功。现在我使用 sqlite 密码作为没有加密密钥的普通数据库。 Create Insert 和 Select Queries 在模拟器中运行良好,但在设备中运行良好。提前致谢。让我知道是否需要其他任何东西来解决我的问题。
-
@Ichthyocentaurs 我按要求添加了代码。