Skip to content

Commit 76cdb2c

Browse files
committed
📝 New Public APIs for iOS
1 parent 32cec4a commit 76cdb2c

File tree

3 files changed

+143
-38
lines changed

3 files changed

+143
-38
lines changed

index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ module.exports = {
116116
Instabug.setUserStepsEnabled(isUserStepsEnabled);
117117
},
118118

119+
/**
120+
* Sets whether IBGLog should also print to Xcode's console log or not.
121+
* @param {boolean} printsToConsole A boolean to set whether printing to
122+
* Xcode's console is enabled or not.
123+
*/
124+
setIBGLogPrintsToConsole: function (printsToConsole) {
125+
if (Platform.OS === 'ios')
126+
Instabug.setIBGLogPrintsToConsole(printsToConsole);
127+
},
128+
119129
/**
120130
* Report un-caught exceptions to Instabug dashboard
121131
* We don't send exceptions from __DEV__, since it's way too noisy!
@@ -146,6 +156,30 @@ module.exports = {
146156

147157
},
148158

159+
/**
160+
* Sets a block of code to be executed when a prompt option is selected.
161+
* @param {function} didSelectPromptOptionHandler - A block of code that
162+
* gets executed when a prompt option is selected.
163+
*/
164+
setDidSelectPromptOptionHandler: function (didSelectPromptOptionHandler) {
165+
if (Platform.OS === 'ios') {
166+
Instabug.addListener('IBGDidSelectPromptOptionHandler');
167+
NativeAppEventEmitter.addListener(
168+
'IBGDidSelectPromptOptionHandler',
169+
function (payload) {
170+
didSelectPromptOptionHandler(payload['promptOption']);
171+
}
172+
);
173+
} else {
174+
DeviceEventEmitter.addListener('IBGDidSelectPromptOptionHandler', function(payload) {
175+
didSelectPromptOptionHandler(payload.promptOption);
176+
});
177+
}
178+
179+
Instabug.didSelectPromptOptionHandler(didSelectPromptOptionHandler);
180+
181+
},
182+
149183
/**
150184
* Shows survey with a specific token.
151185
* Does nothing if there are no available surveys with that specific token.
@@ -277,6 +311,7 @@ module.exports = {
277311
},
278312

279313
/**
314+
* @deprecated Use {@link setInvocationEvents} instead.
280315
* Sets the event that invoke the feedback form.
281316
* Default is set by `Instabug.startWithToken`.
282317
* @param {invocationEvent} invocationEvent Event that invokes the
@@ -286,6 +321,16 @@ module.exports = {
286321
Instabug.setInvocationEvent(invocationEvent);
287322
},
288323

324+
/**
325+
* Sets the events that invoke the feedback form.
326+
* Default is set by `Instabug.startWithToken`.
327+
* @param {invocationEvent} invocationEvent Event that invokes the
328+
* feedback form.
329+
*/
330+
setInvocationEvents: function(invocationEvents) {
331+
Instabug.setInvocationEvents(invocationEvents);
332+
},
333+
289334
/**
290335
* Enables/disables the use of push notifications in the SDK.
291336
* Defaults to YES.
@@ -335,6 +380,8 @@ module.exports = {
335380
},
336381

337382
/**
383+
* @deprecated since version 2.3.0. Use {@link setShakingThresholdForiPhone}
384+
* and {@link setShakingThresholdForiPad} instead.
338385
* Sets the threshold value of the shake gesture for iPhone/iPod Touch and iPad.
339386
* Default for iPhone is 2.5.
340387
* Default for iPad is 0.6.
@@ -346,6 +393,26 @@ module.exports = {
346393
Instabug.setShakingThresholdForIPhone(iPhoneShakingThreshold, iPadShakingThreshold);
347394
},
348395

396+
/**
397+
* Sets the threshold value of the shake gesture for iPhone/iPod Touch
398+
* Default for iPhone is 2.5.
399+
* @param {number} iPhoneShakingThreshold Threshold for iPhone.
400+
*/
401+
setShakingThresholdForiPhone: function (iPhoneShakingThreshold) {
402+
if (Platform.OS === 'ios')
403+
Instabug.setShakingThresholdForiPhone(iPhoneShakingThreshold);
404+
},
405+
406+
/**
407+
* Sets the threshold value of the shake gesture for iPad.
408+
* Default for iPad is 0.6.
409+
* @param {number} iPadShakingThreshold Threshold for iPad.
410+
*/
411+
setShakingThresholdForiPad: function (iPadShakingThreshold) {
412+
if (Platform.OS === 'ios')
413+
Instabug.setShakingThresholdForiPad(iPadShakingThreshold);
414+
},
415+
349416
/**
350417
* Sets the threshold value of the shake gesture for android devices.
351418
* Default for android is an integer value equals 350.

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 69 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#import "InstabugReactBridge.h"
88
#import <Instabug/Instabug.h>
99
#import <Instabug/IBGBugReporting.h>
10+
#import <Instabug/IBGCrashReporting.h>
11+
#import <Instabug/IBGLog.h>
1012
#import <asl.h>
1113
#import <React/RCTLog.h>
1214
#import <os/log.h>
@@ -21,7 +23,8 @@ @implementation InstabugReactBridge
2123
@"IBGpostInvocationHandler",
2224
@"IBGonNewMessageHandler",
2325
@"IBGWillShowSurvey",
24-
@"IBGDidDismissSurvey"
26+
@"IBGDidDismissSurvey",
27+
@"IBGDidSelectPromptOptionHandler"
2528
];
2629
}
2730

@@ -39,7 +42,7 @@ - (dispatch_queue_t)methodQueue {
3942
[Instabug startWithToken:token invocationEvents:invocationEvents];
4043
RCTAddLogFunction(InstabugReactLogFunction);
4144
RCTSetLogThreshold(RCTLogLevelInfo);
42-
[Instabug setNetworkLoggingEnabled:NO];
45+
[IBGNetworkLogger.enabled = NO];
4346
SEL setCrossPlatformSEL = NSSelectorFromString(@"setCrossPlatform:");
4447
if ([[Instabug class] respondsToSelector:setCrossPlatformSEL]) {
4548
[[Instabug class] performSelector:setCrossPlatformSEL withObject:@(true)];
@@ -89,7 +92,7 @@ - (dispatch_queue_t)methodQueue {
8992
}
9093

9194
RCT_EXPORT_METHOD(IBGLog:(NSString *)log) {
92-
[Instabug IBGLog:log];
95+
[IBGLog log:log];
9396
}
9497

9598
RCT_EXPORT_METHOD(showSurveyWithToken:(NSString *)surveyToken) {
@@ -106,50 +109,62 @@ - (dispatch_queue_t)methodQueue {
106109

107110
RCT_EXPORT_METHOD(setCrashReportingEnabled:(BOOL)enabledCrashReporter) {
108111
if(enabledCrashReporter) {
109-
[Instabug setCrashReportingEnabled:YES];
112+
IBGCrashReporting.enabled = YES;
110113
} else {
111-
[Instabug setCrashReportingEnabled:NO];
114+
IBGCrashReporting.enabled = NO;
112115
}
113116
}
114117

115118
RCT_EXPORT_METHOD(setAutoScreenRecordingEnabled:(BOOL)enabled) {
116-
[Instabug setAutoScreenRecordingEnabled:enabled];
119+
Instabug.autoScreenRecordingEnabled = enabled;
117120
}
118121

119122
RCT_EXPORT_METHOD(setAutoScreenRecordingMaxDuration:(CGFloat)duration) {
120-
[Instabug setAutoScreenRecordingDuration:duration];
123+
Instabug.autoScreenRecordingDuration = duration;
121124
}
122125

123126
RCT_EXPORT_METHOD(setPreSendingHandler:(RCTResponseSenderBlock)callBack) {
124127
if (callBack != nil) {
125-
[Instabug setPreSendingHandler:^{
128+
IBGBugReporting.willSendReportHandler = ^{
126129
[self sendEventWithName:@"IBGpreSendingHandler" body:nil];
127-
}];
130+
};
128131
} else {
129-
[Instabug setPreSendingHandler:nil];
132+
IBGBugReporting.willSendReportHandler = nil;
130133
}
131134
}
132135

133136
RCT_EXPORT_METHOD(setPreInvocationHandler:(RCTResponseSenderBlock)callBack) {
134137
if (callBack != nil) {
135-
[Instabug setPreInvocationHandler:^{
138+
IBGBugReporting.willInvokeHandler = ^{
136139
[self sendEventWithName:@"IBGpreInvocationHandler" body:nil];
137-
}];
140+
};
138141
} else {
139-
[Instabug setPreInvocationHandler:nil];
142+
IBGBugReporting.willInvokeHandler = nil;
140143
}
141144
}
142145

143146
RCT_EXPORT_METHOD(setPostInvocationHandler:(RCTResponseSenderBlock)callBack) {
144147
if (callBack != nil) {
145-
[Instabug setPostInvocationHandler:^(IBGDismissType dismissType, IBGReportType reportType) {
148+
IBGBugReporting.didDismissHandler = ^(IBGDismissType dismissType, IBGReportType reportType) {
146149
[self sendEventWithName:@"IBGpostInvocationHandler" body:@{
147150
@"dismissType": @(dismissType),
148151
@"reportType": @(reportType)
149152
}];
150-
}];
153+
};
154+
} else {
155+
IBGBugReporting.didDismissHandler = nil;
156+
}
157+
}
158+
159+
RCT_EXPORT_METHOD(didSelectPromptOptionHandler:(RCTResponseSenderBlock)callBack) {
160+
if (callBack != nil) {
161+
IBGBugReporting.didSelectPromptOptionHandler = ^(IBGPromptOption promptOption) {
162+
[self sendEventWithName:@"IBGDidSelectPromptOptionHandler" body:@{
163+
@"promptOption": @(promptOption)
164+
}];
165+
};
151166
} else {
152-
[Instabug setPostInvocationHandler:nil];
167+
IBGBugReporting.didSelectPromptOptionHandler = nil;
153168
}
154169
}
155170

@@ -170,13 +185,21 @@ - (dispatch_queue_t)methodQueue {
170185
}
171186

172187
RCT_EXPORT_METHOD(getUnreadMessagesCount:(RCTResponseSenderBlock)callBack) {
173-
callBack(@[@([Instabug getUnreadMessagesCount])]);
188+
callBack(@[@(Instabug.unreadMessagesCount)]);
174189
}
175190

176191
RCT_EXPORT_METHOD(setInvocationEvent:(IBGInvocationEvent)invocationEvent) {
177192
[Instabug setInvocationEvent:invocationEvent];
178193
}
179194

195+
RCT_EXPORT_METHOD(setInvocationEvents:(NSArray*)invocationEventsArray) {
196+
IBGInvocationEvent invocationEvents = 0;
197+
for (NSNumber *boxedValue in invocationEventsArray) {
198+
invocationEvents |= [boxedValue intValue];
199+
}
200+
IBGBugReporting.invocationEvents = invocationEvents;
201+
}
202+
180203
RCT_EXPORT_METHOD(setPushNotificationsEnabled:(BOOL)isPushNotificationEnabled) {
181204
[Instabug setPushNotificationsEnabled:isPushNotificationEnabled];
182205
}
@@ -194,28 +217,37 @@ - (dispatch_queue_t)methodQueue {
194217
foriPad:iPadShakingThreshold];
195218
}
196219

220+
RCT_EXPORT_METHOD(setShakingThresholdForiPhone:(double)iPhoneShakingThreshold) {
221+
IBGBugReporting.shakingThresholdForiPhone = iPhoneShakingThreshold;
222+
}
223+
224+
RCT_EXPORT_METHOD(setShakingThresholdForiPad:(double)iPadShakingThreshold) {
225+
IBGBugReporting.shakingThresholdForiPad = iPadShakingThreshold;
226+
}
227+
197228
RCT_EXPORT_METHOD(setFloatingButtonEdge:(CGRectEdge)floatingButtonEdge withTopOffset:(double)floatingButtonOffsetFromTop) {
198-
[Instabug setFloatingButtonEdge:floatingButtonEdge withTopOffset:floatingButtonOffsetFromTop];
229+
IBGBugReporting.floatingButtonEdge = floatingButtonEdge;
230+
IBGBugReporting.floatingButtonTopOffset = floatingButtonOffsetFromTop;
199231
}
200232

201233
RCT_EXPORT_METHOD(setLocale:(IBGLocale)locale) {
202234
[Instabug setLocale:locale];
203235
}
204236

205237
RCT_EXPORT_METHOD(setExtendedBugReportMode:(IBGExtendedBugReportMode)extendedBugReportMode) {
206-
[Instabug setExtendedBugReportMode:extendedBugReportMode];
238+
IBGBugReporting.extendedBugReportMode = extendedBugReportMode;
207239
}
208240

209241
RCT_EXPORT_METHOD(setIntroMessageEnabled:(BOOL)isIntroMessageEnabled) {
210-
[Instabug setIntroMessageEnabled:isIntroMessageEnabled];
242+
IBGBugReporting.introMessageEnabled = isIntroMessageEnabled;
211243
}
212244

213245
RCT_EXPORT_METHOD(setColorTheme:(IBGColorTheme)colorTheme) {
214246
[Instabug setColorTheme:colorTheme];
215247
}
216248

217249
RCT_EXPORT_METHOD(setPrimaryColor:(UIColor *)color) {
218-
[Instabug setPrimaryColor:color];
250+
Instabug.tintColor = color;
219251
}
220252

221253
RCT_EXPORT_METHOD(appendTags:(NSArray *)tags) {
@@ -252,20 +284,20 @@ - (dispatch_queue_t)methodQueue {
252284
attachmentTypes |= IBGAttachmentTypeScreenRecording;
253285
}
254286

255-
[Instabug setEnabledAttachmentTypes:attachmentTypes];
287+
IBGBugReporting.enabledAttachmentTypes = attachmentTypes;
256288
}
257289

258290
RCT_EXPORT_METHOD(setChatNotificationEnabled:(BOOL)isChatNotificationEnabled) {
259-
[Instabug setChatNotificationEnabled:isChatNotificationEnabled];
291+
Instabug.replyNotificationsEnabled = isChatNotificationEnabled;
260292
}
261293

262294
RCT_EXPORT_METHOD(setOnNewMessageHandler:(RCTResponseSenderBlock)callBack) {
263295
if (callBack != nil) {
264-
[Instabug setOnNewMessageHandler:^{
296+
Instabug.didRecieveReplyHandler = ^{
265297
[self sendEventWithName:@"IBGonNewMessageHandler" body:nil];
266-
}];
298+
};
267299
} else {
268-
[Instabug setOnNewMessageHandler:nil];
300+
Instabug.didRecieveReplyHandler = nil;
269301
}
270302
}
271303

@@ -332,7 +364,7 @@ - (dispatch_queue_t)methodQueue {
332364
}
333365

334366
RCT_EXPORT_METHOD(setViewHierarchyEnabled:(BOOL)viewHierarchyEnabled) {
335-
[Instabug setViewHierarchyEnabled:viewHierarchyEnabled];
367+
Instabug.shouldCaptureViewHierarchy = viewHierarchyEnabled;
336368
}
337369

338370
RCT_EXPORT_METHOD(logUserEventWithName:(NSString *)name) {
@@ -343,28 +375,28 @@ - (dispatch_queue_t)methodQueue {
343375
[Instabug logUserEventWithName:name params:params];
344376
}
345377

346-
RCT_EXPORT_METHOD(log:(NSString *)log) {
347-
[Instabug IBGLog:log];
378+
RCT_EXPORT_METHOD(setIBGLogPrintsToConsole:(BOOL) printsToConsole) {
379+
IBGLog.printsToConsole = printsToConsole;
348380
}
349381

350382
RCT_EXPORT_METHOD(logVerbose:(NSString *)log) {
351-
[Instabug logVerbose:log];
383+
[IBGLog logVerbose:log];
352384
}
353385

354386
RCT_EXPORT_METHOD(logDebug:(NSString *)log) {
355-
[Instabug logDebug:log];
387+
[IBGLog logDebug:log];
356388
}
357389

358390
RCT_EXPORT_METHOD(logInfo:(NSString *)log) {
359-
[Instabug logInfo:log];
391+
[IBGLog logInfo:log];
360392
}
361393

362394
RCT_EXPORT_METHOD(logWarn:(NSString *)log) {
363-
[Instabug logWarn:log];
395+
[IBGLog logWarn:log];
364396
}
365397

366398
RCT_EXPORT_METHOD(logError:(NSString *)log) {
367-
[Instabug logError:log];
399+
[IBGLog logError:log];
368400
}
369401

370402
RCT_EXPORT_METHOD(setSurveysEnabled:(BOOL)surveysEnabled) {
@@ -404,7 +436,7 @@ - (dispatch_queue_t)methodQueue {
404436
}
405437

406438
RCT_EXPORT_METHOD(setVideoRecordingFloatingButtonPosition:(IBGPosition)position) {
407-
[Instabug setVideoRecordingFloatingButtonPosition:position];
439+
IBGBugReporting.videoRecordingFloatingButtonPosition = position;
408440
}
409441

410442
RCT_EXPORT_METHOD(setThresholdForReshowingSurveyAfterDismiss:(NSInteger)sessionCount daysCount:(NSInteger)daysCount) {
@@ -416,7 +448,7 @@ - (dispatch_queue_t)methodQueue {
416448
}
417449

418450
RCT_EXPORT_METHOD(showFeatureRequests) {
419-
[Instabug showFeatureRequests];
451+
[IBGFeatureRequests show];
420452
}
421453

422454
RCT_EXPORT_METHOD(setShouldShowSurveysWelcomeScreen:(BOOL)shouldShowWelcomeScreen) {
@@ -431,7 +463,7 @@ - (dispatch_queue_t)methodQueue {
431463
actionTypes |= [boxedValue intValue];
432464
}
433465

434-
[Instabug setEmailFieldRequired:isEmailFieldRequired forAction:actionTypes];
466+
[IBGFeatureRequests setEmailFieldRequired:isEmailFieldRequired forAction:actionTypes];
435467
}
436468

437469
RCT_EXPORT_METHOD(isRunningLive:(RCTResponseSenderBlock)callback) {

0 commit comments

Comments
 (0)