@@ -15,9 +15,13 @@ @implementation IBGPlugin
15
15
*
16
16
* @param {CDVInvokedUrlCommand*} command
17
17
* The command sent from JavaScript
18
+ *
19
+ * @deprecated This method is deprecated. Use `init:` instead.
18
20
*/
19
- - (void ) start : (CDVInvokedUrlCommand*)command
21
+ - (void ) start : (CDVInvokedUrlCommand*)command __deprecated_msg( " This method is deprecated. Use `init:` instead. " )
20
22
{
23
+ NSLog (@" Warning: The `start:` method is deprecated and will be removed in a future version. Please use `init:` instead." );
24
+
21
25
CDVPluginResult* result;
22
26
23
27
NSString * token = [command argumentAtIndex: 0 ];
@@ -45,6 +49,44 @@ - (void) start:(CDVInvokedUrlCommand*)command
45
49
[self .commandDelegate sendPluginResult: result callbackId: [command callbackId ]];
46
50
}
47
51
52
+ - (void )init : (CDVInvokedUrlCommand*)command {
53
+ if (command.arguments == nil || [command.arguments count ] == 0 ) {
54
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: @" Initialization parameters are required." ];
55
+ [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
56
+ return ;
57
+ }
58
+
59
+ @try {
60
+ NSDictionary * options = [command.arguments objectAtIndex: 0 ];
61
+
62
+ NSString * token = options[@" token" ];
63
+ NSArray * invocationEventsArray = options[@" invocationEvents" ];
64
+ NSString * logLevel = options[@" debugLogsLevel" ] ?: @" none" ;
65
+
66
+ if (token == nil || [token isEqualToString: @" " ]) {
67
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: @" Token is required." ];
68
+ [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
69
+ return ;
70
+ }
71
+
72
+ IBGInvocationEvent invocationEvents = 0 ;
73
+ for (NSString * eventName in invocationEventsArray) {
74
+ invocationEvents |= [self parseInvocationEvent: eventName];
75
+ }
76
+
77
+ IBGSDKDebugLogsLevel parsedLogLevel = [self parseLogLevel: logLevel];
78
+
79
+ [Instabug setSdkDebugLogsLevel: parsedLogLevel];
80
+ [Instabug startWithToken: token invocationEvents: invocationEvents];
81
+
82
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
83
+ [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
84
+ } @catch (NSException *exception) {
85
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: [NSString stringWithFormat: @" Error initializing Instabug: %@ " , exception.reason]];
86
+ [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
87
+ }
88
+ }
89
+
48
90
- (void ) identifyUserWithEmail : (CDVInvokedUrlCommand*)command {
49
91
NSString *email = [command argumentAtIndex: 0 ];
50
92
NSString *name = [command argumentAtIndex: 1 ];
@@ -1337,4 +1379,16 @@ - (void)setString:(CDVInvokedUrlCommand*)command {
1337
1379
[Instabug setValue: value forStringWithKey: placeholder];
1338
1380
}
1339
1381
1382
+ - (IBGSDKDebugLogsLevel)parseLogLevel : (NSString *)logLevel {
1383
+ if ([logLevel isEqualToString: @" verbose" ]) {
1384
+ return IBGSDKDebugLogsLevelVerbose;
1385
+ } else if ([logLevel isEqualToString: @" debug" ]) {
1386
+ return IBGSDKDebugLogsLevelDebug;
1387
+ } else if ([logLevel isEqualToString: @" error" ]) {
1388
+ return IBGSDKDebugLogsLevelError;
1389
+ } else {
1390
+ return IBGSDKDebugLogsLevelNone;
1391
+ }
1392
+ }
1393
+
1340
1394
@end
0 commit comments