【问题标题】:SQlite Cipher IOSSQlite 密码 IOS
【发布时间】: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) 但在设备上测试我的应用程序时,它没有显示任何内容。按照我尝试的方式:

  1. 已将 Sqlite 文件保存在包中
  2. Sqlite 文件从包复制到 Document Directory
  3. 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 我按要求添加了代码。

标签: ios swift ipad sqlite


【解决方案1】:

只需启用以下功能:

选择项目->构建设置->架构选项卡->构建发布为YES

确保启用“调试”和“发布”为YES

它将解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    相关资源
    最近更新 更多