Repository: cordova-ios Updated Branches: refs/heads/master 07fd93798 -> 48dfb42b9
CB-10233: Support different config.xml file per CDVViewController instance - Add a configFile property to CDVViewController (path to the config file, absolute or relative to main bundle) - Move loading of settings from -init to -viewDidLoad Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/813a3bac Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/813a3bac Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/813a3bac Branch: refs/heads/master Commit: 813a3bac10320c70a890aaf35ea96a069c6b8e21 Parents: 07fd937 Author: Mirko Luchi <[email protected]> Authored: Tue Dec 22 10:20:31 2015 +0100 Committer: Shazron Abdullah <[email protected]> Committed: Mon Jan 4 16:55:56 2016 -0800 ---------------------------------------------------------------------- CordovaLib/Classes/Public/CDVViewController.h | 1 + CordovaLib/Classes/Public/CDVViewController.m | 42 ++++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/813a3bac/CordovaLib/Classes/Public/CDVViewController.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/Public/CDVViewController.h b/CordovaLib/Classes/Public/CDVViewController.h index 129de02..a8a35d3 100644 --- a/CordovaLib/Classes/Public/CDVViewController.h +++ b/CordovaLib/Classes/Public/CDVViewController.h @@ -44,6 +44,7 @@ @property (nonatomic, readonly, strong) NSMutableDictionary* settings; @property (nonatomic, readonly, strong) NSXMLParser* configParser; +@property (nonatomic, readwrite, copy) NSString* configFile; @property (nonatomic, readwrite, copy) NSString* wwwFolderName; @property (nonatomic, readwrite, copy) NSString* startPage; @property (nonatomic, readonly, strong) CDVCommandQueue* commandQueue; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/813a3bac/CordovaLib/Classes/Public/CDVViewController.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m index b66f524..000d184 100644 --- a/CordovaLib/Classes/Public/CDVViewController.m +++ b/CordovaLib/Classes/Public/CDVViewController.m @@ -82,9 +82,6 @@ [self printMultitaskingInfo]; [self printPlatformVersionWarning]; self.initialized = YES; - - // load config.xml settings - [self loadSettings]; } } @@ -140,16 +137,32 @@ NSLog(@"Multi-tasking -> Device: %@, App: %@", (backgroundSupported ? @"YES" : @"NO"), (![exitsOnSuspend intValue]) ? @"YES" : @"NO"); } -- (void)parseSettingsWithParser:(NSObject <NSXMLParserDelegate>*)delegate -{ - // read from config.xml in the app bundle - NSString* path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"xml"]; +-(NSString*)configFilePath{ + NSString* path = self.configFile ?: @"config.xml"; + // if path is relative, resolve it against the main bundle + if(![path isAbsolutePath]){ + NSString* absolutePath = [[NSBundle mainBundle] pathForResource:path ofType:nil]; + if(!absolutePath){ + NSAssert(NO, @"ERROR: %@ not found in the main bundle!", path); + } + path = absolutePath; + } + + // Assert file exists if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { - NSAssert(NO, @"ERROR: config.xml does not exist. Please run cordova-ios/bin/cordova_plist_to_config_xml path/to/project."); - return; + NSAssert(NO, @"ERROR: %@ does not exist. Please run cordova-ios/bin/cordova_plist_to_config_xml path/to/project.", path); + return nil; } + + return path; +} +- (void)parseSettingsWithParser:(NSObject <NSXMLParserDelegate>*)delegate +{ + // read from config.xml in the app bundle + NSString* path = [self configFilePath]; + NSURL* url = [NSURL fileURLWithPath:path]; self.configParser = [[NSXMLParser alloc] initWithContentsOfURL:url]; @@ -173,8 +186,12 @@ self.settings = delegate.settings; // And the start folder/page. - self.wwwFolderName = @"www"; - self.startPage = delegate.startPage; + if(self.wwwFolderName == nil){ + self.wwwFolderName = @"www"; + } + if(delegate.startPage && self.startPage == nil){ + self.startPage = delegate.startPage; + } if (self.startPage == nil) { self.startPage = @"index.html"; } @@ -252,6 +269,9 @@ - (void)viewDidLoad { [super viewDidLoad]; + + // Load settings + [self loadSettings]; NSString* backupWebStorageType = @"cloud"; // default value --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
