You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2026/09/09 09:49:40 UTC
(cordova-plugin-file) branch master updated: chore(ios): Use `CDVSettingsDictionary` instead of NSMutableDictionary, small refactoring (#657)
This is an automated email from the ASF dual-hosted git repository.
GitToTheHub pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git
The following commit(s) were added to refs/heads/master by this push:
new 928555e chore(ios): Use `CDVSettingsDictionary` instead of NSMutableDictionary, small refactoring (#657)
928555e is described below
commit 928555e9d4e5df163711b9125127669a356839b6
Author: Manuel Beck <ma...@outlook.de>
AuthorDate: Wed Sep 9 11:49:35 2026 +0200
chore(ios): Use `CDVSettingsDictionary` instead of NSMutableDictionary, small refactoring (#657)
- 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 8338c16..9b15a27 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -248,18 +248,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 {
@@ -332,17 +329,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;
@@ -354,7 +345,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
@@ -363,7 +354,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
@@ -380,7 +371,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
[self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
#endif
- [self registerExtraFileSystems:[self getExtraFileSystemsPreference:self.viewController]
+ [self registerExtraFileSystems:[self getExtraFileSystemsPreference]
fromAvailableSet:[self getAvailableFileSystems]];
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org