Reputation: 81
My company has an iOS app in the App Store. We are doing a complete teardown and starting from scratch but pushing it as an update since the old app will not even build. It is old with a lot of dependencies.
In the old app, users have favorited items which are stored in a sqlite database. The new app is storing them in a plist or using sqlite if it means we will not lose data. Is there any way to migrate that data to the new application?
This link makes me think it is possible, but I am not using Titanium: Titanium - Retrieving SQLite Data from previous version of iOS App
I am currently checking to see if the database exists when I launch the app and it is always logging "NO". Any help would be hugely appreciated!
NSString *databaseName = @"my_client_database.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
if (![[NSFileManager defaultManager] fileExistsAtPath:databasePath]){
NSLog(@"NO");
}else{
NSLog(@"YES");
}
Upvotes: 0
Views: 68
Reputation: 81
OK for anyone who needs to query data from a previous application:
This allows you to see exactly where the files are located if you know nothing about the previous version.
Now that you know what you are working with you can look in the appropriate directory. Mine was in application support it turns out.
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSArray *pathsList = [fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
NSURL *directoryURL = [pathsList objectAtIndex:0];
NSString *databasePath = [[directoryURL URLByAppendingPathComponent:@"my_client_database.sqlite"] absoluteString];
At this point you can query the sqlite database and create new records appropriately!
Upvotes: 1