2016-10-05 37 views
3

This here i have shared to show that i have Sqlite file present in copy bundle resources :我在我的iOS應用在Simulator(離線)運行我的應用程序在使用Sqlitecipher它顯示了所有數據的成功和每一個查詢工作正常像(更新,刪除,插入),但測試時我設備上的應用程序不顯示任何內容。從SimulatorSQlite的密碼IOS

  1. 保存Sqlite文件中捆綁
  2. 複製Sqlite文件從包到DocumentDirectory
  3. 刪除應用程序,並重新設置我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"); 
     } 

    }` 

幫助將不勝感激!

+0

你需要分享一些代碼才能在這裏得到答案? – Ichthyocentaurs

+0

你在哪裏使用密碼,並解密數據庫? –

+0

@max_我按照這個Url(https://www.zetetic.net/sqlcipher/ios-tutorial/)中提到的步驟將sqlite密碼集成到我的項目中。並且構建成功。現在,我正在使用sqlite密碼作爲沒有加密密鑰的普通數據庫。創建插入和選擇查詢在模擬器中正常工作,但不在設備中。提前致謝。讓我知道是否需要其他任何東西來解決我的問題。 –

回答

1

只啓用以下內容:

選擇項目 - >構建設置 - >建築選項卡 - >構建釋放到YES

確保啓用調試和釋放YES

它會解決你的問題。

+0

Thanx男人,你剛剛救了我的一天。榮譽:) –

+1

很高興它可以幫助你解決問題。繼續編碼 –