@@ -52,23 +52,30 @@ - (void)show:(CDVInvokedUrlCommand*)command {
5252
5353 NSString *viewControllerName;
5454 NSString *storyboardName;
55+ NSString *uri;
5556 NSString *message;
57+ NSString *firstParam;
5658
5759 NSMutableDictionary * config = [command.arguments objectAtIndex: 0 ];
60+
5861 if ([config isKindOfClass: [NSMutableDictionary class ]]) {
62+
5963 viewControllerName = [config objectForKey: @" viewControllerName" ];
6064 storyboardName = [config objectForKey: @" storyboardName" ];
65+ uri = [config objectForKey: @" uri" ];
66+
6167 } else if ([config isKindOfClass: [NSString class ]]) {
68+
6269 if ([command.arguments count ] == 1 ) {
6370
64- NSString * firstParam = [command argumentAtIndex: 0 ];
71+ firstParam = [command argumentAtIndex: 0 ];
6572
6673 if ([self isValidURI: firstParam]) {
6774 // Open app with valid uri name
6875 [self openAPP: firstParam withCommand: command];
6976
7077 } else if ([firstParam containsString: @" Storyboard" ]) {
71- // Init viewController from Storyboard with initial view Controlleror or user defined viewControllerName
78+ // Init viewController from Storyboard with initial view Controller or user defined viewControllerName
7279 [self instantiateViewController: nil fromStoryboard: firstParam];
7380
7481 } else if ([firstParam containsString: @" Controller" ]) {
@@ -81,65 +88,42 @@ - (void)show:(CDVInvokedUrlCommand*)command {
8188 }
8289
8390 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
91+ return ;
8492
85- } else if ([command.arguments count ] == 2 ) {
93+ }else if ([command.arguments count ] == 2 ) {
8694
8795 // first param is Storyboard
8896 storyboardName = [command argumentAtIndex: 0 ];
8997
9098 // second param is ViewController and/or storyboardId
9199 viewControllerName = [command argumentAtIndex: 1 ];
92100
93- // Init viewController from Storyboard with initial view Controlleror or user defined viewControllerName
94- [self instantiateViewController: viewControllerName fromStoryboard: storyboardName];
95-
96- } else {
101+ }else {
97102 message = [[NSString alloc ] initWithFormat: @" An UIViewController name or Storyboard name or URI valid name is required at least. Please, pass in the first param in JS, like this: 'NativeView.show('MyViewController') or NativeView.show('MyStoryboard') or NativeView.show('MyStoryboard', 'MyViewController') or NativeView.show('instagram://')" ];
98103 @throw [[NSException alloc ] initWithName: @" CLASS_NOT_FOUND_EXCEPTION" reason: message userInfo: nil ];
99104 }
105+
106+ // Init viewController from Storyboard with initial view Controlleror or user defined viewControllerName
107+ [self instantiateViewController: viewControllerName fromStoryboard: storyboardName];
108+
109+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
110+
100111 }else {
101112 @throw [[NSException alloc ] initWithName: @" PARAMS_TYPE_EXCEPTION" reason: @" The params of show() method needs be a string or a json" userInfo: nil ];
102113 }
103114
104- // Handling arguments
105- // if ([command.arguments count] == 1) {
106- //
107- // NSString *firstParam = [command argumentAtIndex: 0];
108- //
109- // if ([self isValidURI: firstParam]) {
110- // // Open app with valid uri name
111- // [self openAPP:firstParam];
112- //
113- // } else if ([firstParam containsString:@"Storyboard"]) {
114- // // Init viewController from Storyboard with initial view Controlleror or user defined viewControllerName
115- // [self instantiateViewController:nil fromStoryboard:firstParam];
116- //
117- // } else if ([firstParam containsString:@"Controller"]) {
118- // // Init viewController with or without xib
119- // [self instantiateViewController:firstParam];
120- //
121- // } else {
122- // message = [[NSString alloc] initWithFormat:@"%@ invalid. Must contain a Storyboard / Controller / URI valid in name", firstParam];
123- // @throw [[NSException alloc] initWithName:@"IO_EXCEPTION" reason:message userInfo:nil];
124- // }
125- //
126- // pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
127- //
128- // } else if ([command.arguments count] == 2) {
129- //
130- // // first param is Storyboard
131- // storyboardName = [command argumentAtIndex: 0];
132- //
133- // // second param is ViewController and/or storyboardId
134- // viewControllerName = [command argumentAtIndex: 1];
135- //
136- // // Init viewController from Storyboard with initial view Controlleror or user defined viewControllerName
137- // [self instantiateViewController:viewControllerName fromStoryboard:storyboardName];
138- //
139- // } else {
140- // message = [[NSString alloc] initWithFormat:@"An UIViewController name or Storyboard name or URI valid name is required at least. Please, pass in the first param in JS, like this: 'NativeView.show('MyViewController') or NativeView.show('MyStoryboard') or NativeView.show('MyStoryboard', 'MyViewController') or NativeView.show('instagram://')"];
141- // @throw [[NSException alloc] initWithName:@"CLASS_NOT_FOUND_EXCEPTION" reason:message userInfo:nil];
142- // }
115+ if ([self isValidURI: uri]) {
116+ // Open app with valid uri name
117+ [self openAPP: uri withCommand: command];
118+
119+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
120+ } else if (viewControllerName != nil || storyboardName != nil ) {
121+ // Init viewController from Storyboard with initial view Controlleror or user defined viewControllerName
122+ [self instantiateViewController: viewControllerName fromStoryboard: storyboardName];
123+
124+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
125+ }
126+
143127 } @catch (NSException *e) {
144128 NSLog (@" [%@ ]: %@ " , e.name , e.reason );
145129
@@ -173,7 +157,6 @@ - (void)showMarket:(CDVInvokedUrlCommand*)command {
173157 NSString *url = [NSString stringWithFormat: @" itms://itunes.apple.com/app/%@ " , appId];
174158
175159 [self openAPP: url withCommand: command];
176- // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
177160
178161 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
179162 } else {
0 commit comments