Skip to content

Commit 1e182f3

Browse files
committed
fix: [iOS] deperecate start api
1 parent e0503bb commit 1e182f3

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

example/package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ios/IBGPlugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@
4343

4444
- (void)setString:(CDVInvokedUrlCommand *)command;
4545

46+
- (void)init:(CDVInvokedUrlCommand *)command;
47+
48+
- (IBGSDKDebugLogsLevel)parseLogLevel:(NSString*)logLevel;
49+
4650
@end

src/ios/IBGPlugin.m

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ @implementation IBGPlugin
1515
*
1616
* @param {CDVInvokedUrlCommand*} command
1717
* The command sent from JavaScript
18+
*
19+
* @deprecated This method is deprecated. Use `init:` instead.
1820
*/
19-
- (void) start:(CDVInvokedUrlCommand*)command
21+
- (void) start:(CDVInvokedUrlCommand*)command __deprecated_msg("This method is deprecated. Use `init:` instead.")
2022
{
23+
NSLog(@"Warning: The `start:` method is deprecated and will be removed in a future version. Please use `init:` instead.");
24+
2125
CDVPluginResult* result;
2226

2327
NSString* token = [command argumentAtIndex:0];
@@ -45,6 +49,44 @@ - (void) start:(CDVInvokedUrlCommand*)command
4549
[self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
4650
}
4751

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+
4890
- (void) identifyUserWithEmail:(CDVInvokedUrlCommand*)command {
4991
NSString *email = [command argumentAtIndex:0];
5092
NSString *name = [command argumentAtIndex:1];
@@ -1337,4 +1379,16 @@ - (void)setString:(CDVInvokedUrlCommand*)command {
13371379
[Instabug setValue:value forStringWithKey:placeholder];
13381380
}
13391381

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+
13401394
@end

0 commit comments

Comments
 (0)