I am working on widget app. I am totally new to Today Extension. I want to share data between app and today extension. I have created one database. I have 4 tables in that database. I found this code to create database for App Groups :
NSString *appGroupId = @"group.appname";
NSURL *appGroupDirectoryPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];
dataBaseURL = [appGroupDirectoryPath URLByAppendingPathComponent:@"database.sqlite"];
NSLog(@"dataBaseURL %@", dataBaseURL);
It worked. My SQLite file has been created. But It does't show my tables. It shows empty database. I don't have any idea about it. Please help.
If you are creating new database then it will obviously empty.
first thing you can create data base with tables in objective c. there is no need to create database from outside the xcode and drag and drop yto xcode. you can refer this techotopia tutorial for that.
Now if you put database in your main bundle by drag and drop then you can access that like,
NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"myDbName" ofType:@"sqlite"];
by this way you can get your database path. here pathforresource is your database name, i think database
in your case and oftype
is extention
, i think sqlite
in your case.
now you get path as string if you want it in url then you can convert it in url like,
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
or
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
Hope this will help :)