Итак, ответы:
-Да, это хороший способ работы, вы можете использовать Интернет для загрузки новейших
данные. Вы можете сделать это двумя способами:
1) Загрузите только новые вопросы и добавьте их в существующий sqlite.
База данных для вашего приложения. Но вы должны знать, что база данных
должен быть помещен в каталог документов вместо вашего приложения
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 и заменить существующую. Это
довольно просто, но помните, что вы должны использовать больше
трафик в этом случае.
- Да, просто храните локальную базу данных в каталоге документов, и
обновите, когда вам нужно.