From 62eb7a28a922d1a892426f94a2278a3ff7541552 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Fri, 12 Jan 2018 16:50:54 +0100 Subject: [PATCH 1/9] Provide shared-location for app groups --- README.md | 1 + SQLitePlugin.coffee.md | 1 + src/ios/SQLitePlugin.m | 19 +++++++++++++++++++ www/SQLitePlugin.js | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6ed5d0d..b645d792 100644 --- a/README.md +++ b/README.md @@ -721,6 +721,7 @@ where the `iosDatabaseLocation` option may be set to one of the following choice - `default`: `Library/LocalDatabase` subdirectory - *NOT* visible to iTunes and *NOT* backed up by iCloud - `Library`: `Library` subdirectory - backed up by iCloud, *NOT* visible to iTunes - `Documents`: `Documents` subdirectory - visible to iTunes and backed up by iCloud +- `Shared`: uses a shared directory depending on the app group specified in the `config.xml` with the preference `SqliteExtSharedGroupId` **WARNING:** Again, the new "default" iosDatabaseLocation value is *NOT* the same as the old default location and would break an upgrade for an app using the old default value (0) on iOS. diff --git a/SQLitePlugin.coffee.md b/SQLitePlugin.coffee.md index 622cb8b1..3cf6af98 100644 --- a/SQLitePlugin.coffee.md +++ b/SQLitePlugin.coffee.md @@ -607,6 +607,7 @@ 'default' : 'nosync' 'Documents' : 'docs' 'Library' : 'libs' + 'Shared' : 'shared' SQLiteFactory = ### diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index 638efdc8..78cf0d32 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -75,6 +75,25 @@ -(void)pluginInitialize [appDBPaths setObject: libs forKey:@"nosync"]; } } + + NSString *preferenceName = @"SqliteExtSharedGroupId"; + NSString *groupId = [self.commandDelegate.settings objectForKey:[preferenceName lowercaseString]]; + BOOL sharedFolderFound = NO; + NSUserDefaults *prefs = [[NSUserDefaults alloc] initWithSuiteName:groupId]; + if(prefs != nil && groupId != nil) { + [prefs synchronize]; + NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupId]; + + if(containerURL != nil) + { + NSString* containerDirectory = [containerURL path]; + + if(containerDirectory != nil) { + sharedFolderFound = YES; + [appDBPaths setObject: containerDirectory forKey:@"shared"]; + } + } + } } } diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 497c3087..319b125a 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -546,7 +546,8 @@ iosLocationMap = { 'default': 'nosync', 'Documents': 'docs', - 'Library': 'libs' + 'Library': 'libs', + 'Shared': 'shared' }; SQLiteFactory = { From cb5d7290bb64245b3d6833d3be490e467fc05961 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Fri, 12 Jan 2018 16:54:51 +0100 Subject: [PATCH 2/9] change preference name --- README.md | 2 +- src/ios/SQLitePlugin.m | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b645d792..1b95410d 100644 --- a/README.md +++ b/README.md @@ -721,7 +721,7 @@ where the `iosDatabaseLocation` option may be set to one of the following choice - `default`: `Library/LocalDatabase` subdirectory - *NOT* visible to iTunes and *NOT* backed up by iCloud - `Library`: `Library` subdirectory - backed up by iCloud, *NOT* visible to iTunes - `Documents`: `Documents` subdirectory - visible to iTunes and backed up by iCloud -- `Shared`: uses a shared directory depending on the app group specified in the `config.xml` with the preference `SqliteExtSharedGroupId` +- `Shared`: uses a shared directory depending on the app group specified in the `config.xml` with the preference `SqliteExtAppGroupId` (something like 'group.de.company.GameContainer') **WARNING:** Again, the new "default" iosDatabaseLocation value is *NOT* the same as the old default location and would break an upgrade for an app using the old default value (0) on iOS. diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index 78cf0d32..00237724 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -76,8 +76,7 @@ -(void)pluginInitialize } } - NSString *preferenceName = @"SqliteExtSharedGroupId"; - NSString *groupId = [self.commandDelegate.settings objectForKey:[preferenceName lowercaseString]]; + NSString *groupId = [self.commandDelegate.settings objectForKey:[@"SqliteExtAppGroupId" lowercaseString]]; BOOL sharedFolderFound = NO; NSUserDefaults *prefs = [[NSUserDefaults alloc] initWithSuiteName:groupId]; if(prefs != nil && groupId != nil) { From b31e356bce23897c67940ebf52fbd31ba5e45500 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Mon, 15 Jan 2018 21:56:26 +0100 Subject: [PATCH 3/9] use directory url instead of group id --- src/ios/SQLitePlugin.m | 27 +++++++++------------------ www/SQLitePlugin.js | 11 +++++------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index 00237724..89ce352c 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -75,24 +75,6 @@ -(void)pluginInitialize [appDBPaths setObject: libs forKey:@"nosync"]; } } - - NSString *groupId = [self.commandDelegate.settings objectForKey:[@"SqliteExtAppGroupId" lowercaseString]]; - BOOL sharedFolderFound = NO; - NSUserDefaults *prefs = [[NSUserDefaults alloc] initWithSuiteName:groupId]; - if(prefs != nil && groupId != nil) { - [prefs synchronize]; - NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupId]; - - if(containerURL != nil) - { - NSString* containerDirectory = [containerURL path]; - - if(containerDirectory != nil) { - sharedFolderFound = YES; - [appDBPaths setObject: containerDirectory forKey:@"shared"]; - } - } - } } } @@ -138,6 +120,10 @@ -(void)openNow: (CDVInvokedUrlCommand*)command // DLog(@"using db location: %@", dblocation); NSString *dbname = [self getDBPath:dbfilename at:dblocation]; + NSString *absoluteURL = [options objectForKey:@"iosDirectoryURL"]; + if (absoluteURL != NULL) { + dbname = absoluteURL; + } if (dbname == NULL) { // XXX NOT EXPECTED (INTERNAL ERROR - XXX TODO SIGNAL ERROR STATUS): @@ -294,6 +280,11 @@ -(void)deleteNow: (CDVInvokedUrlCommand*)command } else { NSString *dbPath = [self getDBPath:dbFileName at:dblocation]; + NSString *absoluteURL = [options objectForKey:@"iosDirectoryURL"]; + if (absoluteURL != NULL) { + dbname = absoluteURL; + } + if ([[NSFileManager defaultManager]fileExistsAtPath:dbPath]) { DLog(@"delete full db path: %@", dbPath); [[NSFileManager defaultManager]removeItemAtPath:dbPath error:nil]; diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 319b125a..eb2553fb 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -546,8 +546,7 @@ iosLocationMap = { 'default': 'nosync', 'Documents': 'docs', - 'Library': 'libs', - 'Shared': 'shared' + 'Library': 'libs' }; SQLiteFactory = { @@ -570,8 +569,8 @@ if (!openargs.name) { throw newSQLError('Database name value is missing in openDatabase call'); } - if (!openargs.iosDatabaseLocation && !openargs.location && openargs.location !== 0) { - throw newSQLError('Database location or iosDatabaseLocation setting is now mandatory in openDatabase call.'); + if (!openargs.iosDatabaseLocation && !openargs.location && openargs.location !== 0 && !openargs.iosDirectoryURL) { + throw newSQLError('Database location, iosDatabaseLocation or iosDirectoryURL setting is now mandatory in openDatabase call.'); } if (!!openargs.location && !!openargs.iosDatabaseLocation) { throw newSQLError('AMBIGUOUS: both location and iosDatabaseLocation settings are present in openDatabase call. Please use either setting, not both.'); @@ -615,8 +614,8 @@ } args.path = dbname; } - if (!first.iosDatabaseLocation && !first.location && first.location !== 0) { - throw newSQLError('Database location or iosDatabaseLocation setting is now mandatory in deleteDatabase call.'); + if (!first.iosDatabaseLocation && !first.location && first.location !== 0 && !openargs.iosDirectoryURL) { + throw newSQLError('Database location, iosDatabaseLocation and iosDirectoryURL setting is now mandatory in deleteDatabase call.'); } if (!!first.location && !!first.iosDatabaseLocation) { throw newSQLError('AMBIGUOUS: both location and iosDatabaseLocation settings are present in deleteDatabase call. Please use either setting value, not both.'); From 1c6a0d6daba2912cbb9871747c8fe277b03a90f5 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Tue, 16 Jan 2018 09:16:54 +0100 Subject: [PATCH 4/9] fix variable --- src/ios/SQLitePlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index 89ce352c..f22e93c8 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -282,7 +282,7 @@ -(void)deleteNow: (CDVInvokedUrlCommand*)command NSString *absoluteURL = [options objectForKey:@"iosDirectoryURL"]; if (absoluteURL != NULL) { - dbname = absoluteURL; + dbPath = absoluteURL; } if ([[NSFileManager defaultManager]fileExistsAtPath:dbPath]) { From 3998d137549e1b703b8d2575df675c0f9ab0275b Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Tue, 16 Jan 2018 10:05:50 +0100 Subject: [PATCH 5/9] use correct variables and small fixes --- src/ios/SQLitePlugin.m | 22 +++++++++++++++------- www/SQLitePlugin.js | 18 +++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index f22e93c8..0bd60eb4 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -88,6 +88,15 @@ -(id) getDBPath:(NSString *)dbFile at:(NSString *)atkey { return dbPath; } +-(id) getDBPath:(NSString *)dbFile inDirectory:(NSString *)directory { + if (dbFile == NULL || directory == NULL) { + return NULL; + } + + NSString *dbPath = [directory stringByAppendingPathComponent: dbFile]; + return dbPath; +} + -(void)echoStringValue: (CDVInvokedUrlCommand*)command { CDVPluginResult * pluginResult = nil; @@ -120,9 +129,9 @@ -(void)openNow: (CDVInvokedUrlCommand*)command // DLog(@"using db location: %@", dblocation); NSString *dbname = [self getDBPath:dbfilename at:dblocation]; - NSString *absoluteURL = [options objectForKey:@"iosDirectoryURL"]; - if (absoluteURL != NULL) { - dbname = absoluteURL; + NSString *directoryURL = [options objectForKey:@"iosDirectoryURL"]; + if (directoryURL != NULL) { + dbname = [self getDBPath:dbfilename inDirectory:directoryURL]; } if (dbname == NULL) { @@ -279,10 +288,9 @@ -(void)deleteNow: (CDVInvokedUrlCommand*)command pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"You must specify database path"]; } else { NSString *dbPath = [self getDBPath:dbFileName at:dblocation]; - - NSString *absoluteURL = [options objectForKey:@"iosDirectoryURL"]; - if (absoluteURL != NULL) { - dbPath = absoluteURL; + NSString *directoryURL = [options objectForKey:@"iosDirectoryURL"]; + if (directoryURL != NULL) { + dbPath = [self getDBPath:dbFileName inDirectory:directoryURL]; } if ([[NSFileManager defaultManager]fileExistsAtPath:dbPath]) { diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index eb2553fb..01cb7b35 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -575,9 +575,11 @@ if (!!openargs.location && !!openargs.iosDatabaseLocation) { throw newSQLError('AMBIGUOUS: both location and iosDatabaseLocation settings are present in openDatabase call. Please use either setting, not both.'); } - dblocation = !!openargs.location && openargs.location === 'default' ? iosLocationMap['default'] : !!openargs.iosDatabaseLocation ? iosLocationMap[openargs.iosDatabaseLocation] : dblocations[openargs.location]; - if (!dblocation) { - throw newSQLError('Valid iOS database location could not be determined in openDatabase call'); + if (!openargs.iosDirectoryURL) { + dblocation = !!openargs.location && openargs.location === 'default' ? iosLocationMap['default'] : !!openargs.iosDatabaseLocation ? iosLocationMap[openargs.iosDatabaseLocation] : dblocations[openargs.location]; + if (!dblocation) { + throw newSQLError('Valid iOS database location could not be determined in openDatabase call'); + } } openargs.dblocation = dblocation; if (!!openargs.createFromLocation && openargs.createFromLocation === 1) { @@ -614,15 +616,17 @@ } args.path = dbname; } - if (!first.iosDatabaseLocation && !first.location && first.location !== 0 && !openargs.iosDirectoryURL) { + if (!first.iosDatabaseLocation && !first.location && first.location !== 0 && !first.iosDirectoryURL) { throw newSQLError('Database location, iosDatabaseLocation and iosDirectoryURL setting is now mandatory in deleteDatabase call.'); } if (!!first.location && !!first.iosDatabaseLocation) { throw newSQLError('AMBIGUOUS: both location and iosDatabaseLocation settings are present in deleteDatabase call. Please use either setting value, not both.'); } - dblocation = !!first.location && first.location === 'default' ? iosLocationMap['default'] : !!first.iosDatabaseLocation ? iosLocationMap[first.iosDatabaseLocation] : dblocations[first.location]; - if (!dblocation) { - throw newSQLError('Valid iOS database location could not be determined in deleteDatabase call'); + if (!first.iosDirectoryURL) { + dblocation = !!first.location && first.location === 'default' ? iosLocationMap['default'] : !!first.iosDatabaseLocation ? iosLocationMap[first.iosDatabaseLocation] : dblocations[first.location]; + if (!dblocation) { + throw newSQLError('Valid iOS database location could not be determined in deleteDatabase call'); + } } args.dblocation = dblocation; delete SQLitePlugin.prototype.openDBs[args.path]; From ccbff110f47dfd07b942414ea47b1d4449468119 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Tue, 16 Jan 2018 11:04:01 +0100 Subject: [PATCH 6/9] use correct function --- src/ios/SQLitePlugin.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index 0bd60eb4..83abb2ba 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -84,15 +84,14 @@ -(id) getDBPath:(NSString *)dbFile at:(NSString *)atkey { } NSString *dbdir = [appDBPaths objectForKey:atkey]; - NSString *dbPath = [dbdir stringByAppendingPathComponent: dbFile]; - return dbPath; + return [self getDBPath:dbFile inDirectory:dbdir]; } -(id) getDBPath:(NSString *)dbFile inDirectory:(NSString *)directory { if (dbFile == NULL || directory == NULL) { return NULL; } - + NSString *dbPath = [directory stringByAppendingPathComponent: dbFile]; return dbPath; } From 26167f50488424490418aa981723f028bff96056 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger <> Date: Wed, 31 Jan 2018 21:04:02 +0100 Subject: [PATCH 7/9] set iosDirectoryLocation in deleteDatabase arguments --- www/SQLitePlugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 01cb7b35..c59f0364 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -627,8 +627,10 @@ if (!dblocation) { throw newSQLError('Valid iOS database location could not be determined in deleteDatabase call'); } + args.dblocation = dblocation; + } else { + args.iosDirectoryURL = first.iosDirectoryURL; } - args.dblocation = dblocation; delete SQLitePlugin.prototype.openDBs[args.path]; return cordova.exec(success, error, "SQLitePlugin", "delete", [args]); } From d600a664e82b00819c8477f55354099ff5d747bb Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Wed, 31 Jan 2018 21:04:02 +0100 Subject: [PATCH 8/9] set iosDirectoryLocation in deleteDatabase arguments --- www/SQLitePlugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 01cb7b35..c59f0364 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -627,8 +627,10 @@ if (!dblocation) { throw newSQLError('Valid iOS database location could not be determined in deleteDatabase call'); } + args.dblocation = dblocation; + } else { + args.iosDirectoryURL = first.iosDirectoryURL; } - args.dblocation = dblocation; delete SQLitePlugin.prototype.openDBs[args.path]; return cordova.exec(success, error, "SQLitePlugin", "delete", [args]); } From a72b395b1d6ce9875460922e0344fa37c2d20006 Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Fri, 14 Jun 2019 12:52:11 +0200 Subject: [PATCH 9/9] Remove not used location --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1b95410d..c6ed5d0d 100644 --- a/README.md +++ b/README.md @@ -721,7 +721,6 @@ where the `iosDatabaseLocation` option may be set to one of the following choice - `default`: `Library/LocalDatabase` subdirectory - *NOT* visible to iTunes and *NOT* backed up by iCloud - `Library`: `Library` subdirectory - backed up by iCloud, *NOT* visible to iTunes - `Documents`: `Documents` subdirectory - visible to iTunes and backed up by iCloud -- `Shared`: uses a shared directory depending on the app group specified in the `config.xml` with the preference `SqliteExtAppGroupId` (something like 'group.de.company.GameContainer') **WARNING:** Again, the new "default" iosDatabaseLocation value is *NOT* the same as the old default location and would break an upgrade for an app using the old default value (0) on iOS.