所以答案:
是的,這是工作的好方法,你可以使用網絡上傳最新 數據。你可以用兩種方法做:
1)只上傳新問題,並將它們添加到現有的sqlite 數據庫爲您的應用程序。但是您應該知道,數據庫 必須放置在Documents目錄中,而不是您的應用程序 Bundle中。示例代碼,你可以在這裏查看。
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"db.sqlite"];
self.imagesPath = [documentsDirectory stringByAppendingPathComponent:@"images"];
//Check if you have local copy of your database
if (![fileManager fileExistsAtPath:imagesPath])
{
NSError *error;
if (![fileManager createDirectoryAtPath:imagesPath withIntermediateDirectories:YES
attributes:NULL error:&error])
{
NSAssert1(0, @"Error cannot create a directory %@", imagesPath);
}
}
success = [fileManager fileExistsAtPath:writableDBPath];
//If you have no local copy, than copy default database, which you have added to project
//Instead of this you can also download database from internet.
if (!success)
{
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
2)你可以下載整個sqlite數據庫並替換現有的。它很容易,但請記住,在這種情況下,您應該使用更多的流量。
- 是的,只是存儲在本地數據庫中的文件目錄,當你需要
更新。
如果我理解正確,應用程序「Exoplanet」解決您的問題的方式是,只要包含行星的文檔(在您的情況下,您的Q/A)就會在應用程序頂部彈出小紅點警報,變化。然後,應用程序知道它應該去獲取它,並將內容存儲在手機SQLite數據庫中。 – Kheldar