@@ -22,22 +22,22 @@ - (instancetype)init
22
22
self = [super init ];
23
23
if (self) {
24
24
self.resultExceptions = @{
25
- @" IO_EXCEPTION " : ^{
25
+ @" IoException " : ^{
26
26
return CDVCommandStatus_IO_EXCEPTION;
27
27
},
28
- @" CLASS_NOT_FOUND_EXCEPTION " : ^{
28
+ @" NotFoundException " : ^{
29
29
return CDVCommandStatus_CLASS_NOT_FOUND_EXCEPTION;
30
30
},
31
- @" PARAM_INVALID_EXCEPTION " : ^{
31
+ @" ParamInvalidException " : ^{
32
32
return CDVCommandStatus_ERROR;
33
33
},
34
- @" INSTANTIATION_EXCEPTION " : ^{
34
+ @" InstantiationException " : ^{
35
35
return CDVCommandStatus_INSTANTIATION_EXCEPTION;
36
36
},
37
- @" NOT_FOUND_EXCEPTION " : ^{
37
+ @" NoResultException " : ^{
38
38
return CDVCommandStatus_NO_RESULT;
39
39
},
40
- @" PARAMS_TYPE_EXCEPTION " : ^{
40
+ @" ParamsTypeException " : ^{
41
41
return CDVCommandStatus_INVALID_ACTION;
42
42
}
43
43
};
@@ -84,7 +84,7 @@ - (void)show:(CDVInvokedUrlCommand*)command {
84
84
85
85
} else {
86
86
message = [[NSString alloc ] initWithFormat: @" %@ invalid. Must contain a Storyboard / Controller / URI valid in name" , firstParam];
87
- @throw [[NSException alloc ] initWithName: @" IO_EXCEPTION " reason: message userInfo: nil ];
87
+ @throw [[NSException alloc ] initWithName: @" IoException " reason: message userInfo: nil ];
88
88
}
89
89
90
90
pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
@@ -100,16 +100,11 @@ - (void)show:(CDVInvokedUrlCommand*)command {
100
100
101
101
}else {
102
102
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://')" ];
103
- @throw [[NSException alloc ] initWithName: @" CLASS_NOT_FOUND_EXCEPTION " reason: message userInfo: nil ];
103
+ @throw [[NSException alloc ] initWithName: @" NotFoundException " reason: message userInfo: nil ];
104
104
}
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
105
111
106
}else {
112
- @throw [[NSException alloc ] initWithName: @" PARAMS_TYPE_EXCEPTION " reason: @" The params of show() method needs be a string or a json" userInfo: nil ];
107
+ @throw [[NSException alloc ] initWithName: @" ParamsTypeException " reason: @" The params of show() method needs be a string or a json" userInfo: nil ];
113
108
}
114
109
115
110
if ([self isValidURI: uri]) {
@@ -132,7 +127,13 @@ - (void)show:(CDVInvokedUrlCommand*)command {
132
127
CaseBlock c = self.resultExceptions [e.name];
133
128
134
129
CDVCommandStatus exceptionType = c ? c () : CDVCommandStatus_ERROR;
135
- pluginResult = [CDVPluginResult resultWithStatus: exceptionType messageAsString: e.reason];
130
+ NSDictionary * error = @{
131
+ @" success" : @NO ,
132
+ @" name" : e.name ,
133
+ @" message" : e.reason
134
+ };
135
+
136
+ pluginResult = [CDVPluginResult resultWithStatus: exceptionType messageAsDictionary: error];
136
137
}
137
138
138
139
[self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
@@ -160,7 +161,13 @@ - (void)showMarket:(CDVInvokedUrlCommand*)command {
160
161
161
162
pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
162
163
} else {
163
- pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_INVALID_ACTION messageAsString: @" Invalid application id: the parameter 'marketId' is invalid" ];
164
+ NSDictionary * error = @{
165
+ @" success" : @NO ,
166
+ @" name" : @" ParamInvalidException" ,
167
+ @" message" : @" Invalid application id: the parameter 'marketId' is invalid"
168
+ };
169
+
170
+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_INVALID_ACTION messageAsDictionary: error];
164
171
}
165
172
166
173
[self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
@@ -178,23 +185,36 @@ - (void)checkIfAppInstalled:(CDVInvokedUrlCommand*)command {
178
185
uri = [config objectForKey: @" uri" ];
179
186
180
187
if (uri == nil ) {
181
- @throw [[NSException alloc ] initWithName: @" PARAMS_TYPE_EXCEPTION " reason: @" The 'uri' key is required" userInfo: nil ];
188
+ @throw [[NSException alloc ] initWithName: @" ParamsTypeException " reason: @" The 'uri' key is required" userInfo: nil ];
182
189
}
183
190
}else if ([config isKindOfClass: [NSString class ]]) {
184
191
uri = (NSString *) config;
185
192
}else {
186
- @throw [[NSException alloc ] initWithName: @" PARAMS_TYPE_EXCEPTION " reason: @" The params of checkIfAppInstalled() method needs be a string or a json" userInfo: nil ];
193
+ @throw [[NSException alloc ] initWithName: @" ParamsTypeException " reason: @" The params of checkIfAppInstalled() method needs be a string or a json" userInfo: nil ];
187
194
}
188
195
189
196
if (![self isValidURI: uri]) {
190
197
NSString *message = [[NSString alloc ] initWithFormat: @" uri param invalid: %@ " , uri];
191
- pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: message];
198
+ NSDictionary * error = @{
199
+ @" success" : @NO ,
200
+ @" name" : @" ParamInvalidException" ,
201
+ @" message" : message
202
+ };
203
+
204
+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: error];
192
205
} else {
193
206
if ([[UIApplication sharedApplication ] canOpenURL: [NSURL URLWithString: uri]]) {
194
207
pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsBool: (true )];
195
208
}
196
209
else {
197
- pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsBool: (false )];
210
+ NSString *message = [[NSString alloc ] initWithFormat: @" The app that responds to URI: %@ was not found" , uri];
211
+ NSDictionary * error = @{
212
+ @" success" : @NO ,
213
+ @" name" : @" NotFoundException" ,
214
+ @" message" : message
215
+ };
216
+
217
+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_CLASS_NOT_FOUND_EXCEPTION messageAsDictionary: error];
198
218
}
199
219
}
200
220
} @catch (NSException *e) {
@@ -205,7 +225,12 @@ - (void)checkIfAppInstalled:(CDVInvokedUrlCommand*)command {
205
225
CaseBlock c = self.resultExceptions [e.name];
206
226
207
227
CDVCommandStatus exceptionType = c ? c () : CDVCommandStatus_ERROR;
208
- pluginResult = [CDVPluginResult resultWithStatus: exceptionType messageAsString: e.reason];
228
+ NSDictionary * error = @{
229
+ @" success" : @NO ,
230
+ @" name" : e.name ,
231
+ @" message" : e.reason
232
+ };
233
+ pluginResult = [CDVPluginResult resultWithStatus: exceptionType messageAsDictionary: error];
209
234
} @finally {
210
235
[self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
211
236
}
@@ -243,7 +268,7 @@ - (void) instantiateViewController:(NSString *)viewControllerName {
243
268
}
244
269
} @catch (NSException *e) {
245
270
message = [[NSString alloc ] initWithFormat: @" %@ and/or its own xib does not exist. \n Detail: %@ " , viewControllerName, e.reason];
246
- @throw [[NSException alloc ] initWithName: @" CLASS_NOT_FOUND_EXCEPTION " reason: message userInfo: nil ];
271
+ @throw [[NSException alloc ] initWithName: @" NotFoundException " reason: message userInfo: nil ];
247
272
}
248
273
}
249
274
@@ -252,7 +277,7 @@ - (void) instantiateViewController:(NSString *)viewControllerName {
252
277
253
278
} else {
254
279
message = [[NSString alloc ] initWithFormat: @" UIViewController with name %@ was not found" , viewControllerName];
255
- @throw [[NSException alloc ] initWithName: @" PARAM_INVALID_EXCEPTION " reason: message userInfo: nil ];
280
+ @throw [[NSException alloc ] initWithName: @" ParamInvalidException " reason: message userInfo: nil ];
256
281
}
257
282
}
258
283
@@ -291,7 +316,7 @@ - (void) instantiateViewController:(NSString *)viewControllerName fromStoryboard
291
316
}
292
317
} @catch (NSException *e) {
293
318
NSString *detailMessage = [[NSString alloc ] initWithFormat: @" %@ \n Detail: %@ " , message, e.reason];
294
- @throw [[NSException alloc ] initWithName: @" INSTANTIATION_EXCEPTION " reason: detailMessage userInfo: nil ];
319
+ @throw [[NSException alloc ] initWithName: @" NotFoundException " reason: detailMessage userInfo: nil ];
295
320
}
296
321
}
297
322
@@ -300,7 +325,7 @@ - (void) instantiateViewController:(NSString *)viewControllerName fromStoryboard
300
325
301
326
} else {
302
327
message = [[NSString alloc ] initWithFormat: @" Storyboard %@ was not found" , storyboardName];
303
- @throw [[NSException alloc ] initWithName: @" PARAM_INVALID_EXCEPTION " reason: message userInfo: nil ];
328
+ @throw [[NSException alloc ] initWithName: @" ParamInvalidException " reason: message userInfo: nil ];
304
329
}
305
330
}
306
331
@@ -322,7 +347,13 @@ - (void) openAPP:(NSString *)uriValue withCommand:(CDVInvokedUrlCommand*) comman
322
347
NSString * message = @" APP with uri %@ not found." ;
323
348
NSLog (message, uriValue);
324
349
325
- pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_INSTANTIATION_EXCEPTION messageAsString: [[NSString alloc ] initWithFormat: message, uriValue]];
350
+ NSDictionary * error = @{
351
+ @" success" : @NO ,
352
+ @" name" : @" InstantiationException" ,
353
+ @" message" : [[NSString alloc ] initWithFormat: message, uriValue]
354
+ };
355
+
356
+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_INSTANTIATION_EXCEPTION messageAsDictionary: error];
326
357
} else {
327
358
NSString * message = @" APP with uri %@ opened." ;
328
359
NSLog (message, uriValue);
0 commit comments