所以答案:
是的,这是工作的好方法,你可以使用网络上传最新 数据。你可以用两种方法做:
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