This is an automated email from the ASF dual-hosted git repository. GitToTheHub pushed a commit to branch pr-ios-use-CDVSettingsDictionary in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git
commit 4008688ab741c8427cd8ee899d93aab6b8330bf9 Author: Manuel Beck <[email protected]> AuthorDate: Fri Jul 31 19:10:00 2026 +0200 chore(ios): Use `CDVSettingsDictionary` instead of NSMutableDictionary, small refactoring - self.viewController.settings was assigned to a local variable typed `NSMutableDictionary`. ` self.viewController.settings` is used directly. - Add type alias NSDictionary to CDVSettingsDictionary when using cordova-ios 7 and older - Don't check if self.viewController is kind of class CDVViewController. CDVViewController was introduced in Cordova 2.0.0. - Refactored method `getExtraFileSystemsPreference` --- src/ios/CDVFile.h | 10 ++++++++++ src/ios/CDVFile.m | 37 ++++++++++++++----------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h index 987c66b..617edef 100644 --- a/src/ios/CDVFile.h +++ b/src/ios/CDVFile.h @@ -20,6 +20,16 @@ #import <Foundation/Foundation.h> #import <Cordova/CDVPlugin.h> + +#ifndef __CORDOVA_8_0_0 +#import <Cordova/NSDictionary+CordovaPreferences.h> +// cordova-ios 8 introduced CDVSettingsDictionary, which should be used +// instead of NSDictionary+CordovaPreferences +// For cordova-ios 7 and earlier, we create a type alias for NSDictionary to CDVSettingsDictionary, +// so that a symbolic "CDVSettingsDictionary" can be used in these older cordova-ios versions. +typedef NSDictionary CDVSettingsDictionary; +#endif + extern NSString* const kCDVAssetsLibraryPrefix; extern NSString* const kCDVFilesystemURLPrefix; diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m index 59e7d64..f1bd3f0 100644 --- a/src/ios/CDVFile.m +++ b/src/ios/CDVFile.m @@ -238,18 +238,15 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; } } -- (NSArray *)getExtraFileSystemsPreference:(UIViewController *)vc +- (NSArray *)getExtraFileSystemsPreference { - NSString *filesystemsStr = nil; - if([self.viewController isKindOfClass:[CDVViewController class]]) { - CDVViewController *vc = (CDVViewController *)self.viewController; - NSDictionary *settings = [vc settings]; - filesystemsStr = [settings[@"iosextrafilesystems"] lowercaseString]; - } - if (!filesystemsStr) { - filesystemsStr = @"library,library-nosync,documents,documents-nosync,cache,bundle,root"; + NSString *extraFileSystems = [[self.viewController.settings objectForKey:@"iosextrafilesystems"] lowercaseString]; + + if (!extraFileSystems) { + extraFileSystems = @"library,library-nosync,documents,documents-nosync,cache,bundle,root"; } - return [filesystemsStr componentsSeparatedByString:@","]; + + return [extraFileSystems componentsSeparatedByString:@","]; } - (void)makeNonSyncable:(NSString*)path { @@ -322,17 +319,11 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; self.rootDocsPath = [paths objectAtIndex:0]; self.appDocsPath = [self.rootDocsPath stringByAppendingPathComponent:@"files"]; + NSString *persistentFileLocation = [[self.viewController.settings objectForKey:@"iospersistentfilelocation"] lowercaseString]; - NSString *location = nil; - if([self.viewController isKindOfClass:[CDVViewController class]]) { - CDVViewController *vc = (CDVViewController *)self.viewController; - NSMutableDictionary *settings = vc.settings; - location = [[settings objectForKey:@"iospersistentfilelocation"] lowercaseString]; - } - if (location == nil) { - // Compatibilty by default (if the config preference is not set, or - // if we're not embedded in a CDVViewController somehow.) - location = @"compatibility"; + // Compatibilty by default (if the config preference is not set) + if (persistentFileLocation == nil) { + persistentFileLocation = @"compatibility"; } NSError *error; @@ -344,7 +335,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; } else { NSLog(@"Unable to create temporary directory: %@", error); } - if ([location isEqualToString:@"library"]) { + if ([persistentFileLocation isEqualToString:@"library"]) { if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appLibraryPath withIntermediateDirectories:YES attributes:nil @@ -353,7 +344,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; } else { NSLog(@"Unable to create library directory: %@", error); } - } else if ([location isEqualToString:@"compatibility"]) { + } else if ([persistentFileLocation isEqualToString:@"compatibility"]) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so @@ -368,7 +359,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; } [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]]; - [self registerExtraFileSystems:[self getExtraFileSystemsPreference:self.viewController] + [self registerExtraFileSystems:[self getExtraFileSystemsPreference] fromAvailableSet:[self getAvailableFileSystems]]; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
