iOS 8 - Create SQLite database for App Group iOS 8 - Create SQLite database for App Group sqlite sqlite

iOS 8 - Create SQLite database for App Group


You have to create a database file in the containing app in the app group directory too.So the containing app and the app extension will use the same file path to a database file.

NSString *appGroupId = @"group.YourAPP.extension";NSURL *appGroupDirectoryPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];NSURL *dataBaseURL = [directory  URLByAppendingPathComponent:@"dbName.db"];

So by this way, you're creating the database file in the containing app and in the app extension you're getting the database file by the same way.


func getTheFilePath() -> String{     var url = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.spanglish.www") as NSURL?     var path = url?.absoluteString?.stringByAppendingPathComponent("English.txt") as String?     path = path!.stringByReplacingOccurrencesOfString("file:", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)     return path!}

You can get path of container app path where you can create sqlite file and can access from both container app and extension app as well.
Please keep in mind that "Allow full Access" must be On for get path from this method