2012-01-26 49 views
0

我的應用程序在其NSBundle中有一個數據庫文件。每當有新的數據庫文件可用時,我都想從互聯網上獲取更新數據庫文件。這應該在應用程序顯示來自數據庫文件的數據之前發生。 這是我正在嘗試使用的邏輯。我不知道它是否有意義,或者是否有更好的方法來做到這一點。一個例子是真棒如何通過互聯網更新數據庫文件?

if (file is available in the Documents Directory) 
{ 
    if(check if internet is available) 
    { 
     1. get file from network 
     2. store it in Documents Directory 
     if (compare contents of the old & new file) 
     { 
      delete downloaded file 
     } else { 
      move or delete old file & rename new file (so that the new file's data can be accessed) 
     } 
    } else { 
     use old file in Documents Directory 
    } 
} else { 
    copy file from bundle to Documents Directory 
} 

回答

3

理想情況下,你應該有你的手機上的數據庫副本的時間戳或版本號,並傳送到服務器。然後讓服務器只發送一個新的副本,如果有更新的版本。爲用戶節省大量的數據費用。

+0

同意。不要傳輸整個數據庫。您可能還想閱讀數據庫版本控制。 http://www.codinghorror.com/blog/2008/02/get-your-database-under-version-control.html – DougW

+0

Hot Licks&DougW,感謝您的指導。你能指點我一些教程鏈接或示例代碼,可以幫助我。 – Hitz

+0

@Hitz - 一般來說,您應該使用REST界面。一旦你可以與REST接口進行交互,那麼細節就相當簡單(或者更復雜一點,如果你想進行部分更新 - 這取決於你)。 –