diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h index 81ebe3d1b..811e5f2e3 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h @@ -13,6 +13,7 @@ NS_SWIFT_NAME(InstanceConfiguration) @property (nonatomic, readonly, nonnull) NSArray *allowedNavigationHostnames; @property (nonatomic, readonly, nonnull) NSURL *localURL; @property (nonatomic, readonly, nonnull) NSURL *serverURL; +@property (nonatomic, readonly, nullable) NSURL *configURL; @property (nonatomic, readonly, nullable) NSString *errorPath; @property (nonatomic, readonly, nonnull) NSDictionary *pluginConfigurations; @property (nonatomic, readonly) BOOL loggingEnabled; diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m index 0bb8ecd8f..bcf56e99e 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m @@ -48,6 +48,13 @@ - (instancetype)initWithDescriptor:(CAPInstanceDescriptor *)descriptor isDebug:( else { _serverURL = _localURL; } + + if (descriptor.configUrl != nil) { + _configURL = descriptor.configUrl; + } + else { + _configURL = [[NSURL alloc] initWithString:(@"capacitor.config.json")]; + } _errorPath = descriptor.errorPath; // extract the one value we care about from the cordova configuration _cordovaDeployDisabled = [descriptor cordovaDeployDisabled]; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h index 228b3a41d..20e9dacc9 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h @@ -68,6 +68,11 @@ NS_SWIFT_NAME(InstanceDescriptor) @discussion Defaults to nil, in which case the server URL will be constructed from @c urlScheme and @c urlHostname. If set, it will override the other properties. Set by @c server.url in the configuration file. */ @property (nonatomic, copy, nullable) NSString *serverURL; +/** + @brief The file URL from which Capacitor will load configuration + @discussion Defaults to @c capacitor.config.json located at the root of the application bundle. + */ +@property (nonatomic, copy, nullable) NSURL *configUrl; /** @brief The JSON dictionary that contains the plugin-specific configuration information. @discussion Set by @c plugins in the configuration file. diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift index 9645d005e..6d768fd9a 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift @@ -30,6 +30,8 @@ internal extension InstanceDescriptor { // swiftlint:disable function_body_length // swiftlint:disable:next identifier_name @objc func _parseConfiguration(at capacitorURL: URL?, cordovaConfiguration cordovaURL: URL?) { + configUrl = capacitorURL + // sanity check that the app directory is valid var isDirectory: ObjCBool = ObjCBool(false) if warnings.contains(.missingAppDir) == false, diff --git a/ios/Capacitor/Capacitor/CapacitorBridge.swift b/ios/Capacitor/Capacitor/CapacitorBridge.swift index 06e52711a..3c8a25ba4 100644 --- a/ios/Capacitor/Capacitor/CapacitorBridge.swift +++ b/ios/Capacitor/Capacitor/CapacitorBridge.swift @@ -284,10 +284,9 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol { */ func registerPlugins() { var pluginList: [AnyClass] = [CAPHttpPlugin.self, CAPConsolePlugin.self, CAPWebViewPlugin.self, CAPCookiesPlugin.self] - - if autoRegisterPlugins { + if autoRegisterPlugins && config.configURL != nil { do { - if let pluginJSON = Bundle.main.url(forResource: "capacitor.config", withExtension: "json") { + if let pluginJSON = Bundle.main.url(forResource: (config.configURL!.path as NSString).deletingPathExtension, withExtension: "json") { let pluginData = try Data(contentsOf: pluginJSON) let registrationList = try JSONDecoder().decode(RegistrationList.self, from: pluginData)