-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathBugReportingApi.m
185 lines (146 loc) · 7.29 KB
/
BugReportingApi.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#import <Flutter/Flutter.h>
#import "Instabug.h"
#import "BugReportingApi.h"
#import "ArgsRegistry.h"
extern void InitBugReportingApi(id<FlutterBinaryMessenger> messenger) {
BugReportingFlutterApi *flutterApi = [[BugReportingFlutterApi alloc] initWithBinaryMessenger:messenger];
BugReportingApi *api = [[BugReportingApi alloc] initWithFlutterApi:flutterApi];
BugReportingHostApiSetup(messenger, api);
}
@implementation BugReportingApi
- (instancetype)initWithFlutterApi:(BugReportingFlutterApi *)api {
self = [super init];
self.flutterApi = api;
return self;
}
- (void)setEnabledIsEnabled:(NSNumber *)isEnabled error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReporting.enabled = [isEnabled boolValue];
}
- (void)showReportType:(NSString *)reportType invocationOptions:(NSArray<NSString *> *)invocationOptions error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReportingReportType resolvedType = (ArgsRegistry.reportTypes[reportType]).integerValue;
IBGBugReportingOption resolvedOptions = 0;
for (NSString *option in invocationOptions) {
resolvedOptions |= (ArgsRegistry.invocationOptions[option]).integerValue;
}
[IBGBugReporting showWithReportType:resolvedType options:resolvedOptions];
}
- (void)setInvocationEventsEvents:(NSArray<NSString *> *)events error:(FlutterError *_Nullable *_Nonnull)error {
IBGInvocationEvent resolvedEvents = 0;
for (NSString *event in events) {
resolvedEvents |= (ArgsRegistry.invocationEvents[event]).integerValue;
}
IBGBugReporting.invocationEvents = resolvedEvents;
}
- (void)setReportTypesTypes:(NSArray<NSString *> *)types error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReportingReportType resolvedTypes = 0;
for (NSString *type in types) {
resolvedTypes |= (ArgsRegistry.reportTypes[type]).integerValue;
}
[IBGBugReporting setPromptOptionsEnabledReportTypes:resolvedTypes];
}
- (void)setExtendedBugReportModeMode:(NSString *)mode error:(FlutterError *_Nullable *_Nonnull)error {
IBGExtendedBugReportMode resolvedMode = (ArgsRegistry.extendedBugReportStates[mode]).integerValue;
IBGBugReporting.extendedBugReportMode = resolvedMode;
}
- (void)setInvocationOptionsOptions:(NSArray<NSString *> *)options error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReportingOption resolvedOptions = 0;
for (NSString *option in options) {
resolvedOptions |= (ArgsRegistry.invocationOptions[option]).integerValue;
}
IBGBugReporting.bugReportingOptions = resolvedOptions;
}
- (void)setFloatingButtonEdgeEdge:(NSString *)edge offset:(NSNumber *)offset error:(FlutterError *_Nullable *_Nonnull)error {
CGRectEdge resolvedEdge = (ArgsRegistry.floatingButtonEdges[edge]).doubleValue;
IBGBugReporting.floatingButtonEdge = resolvedEdge;
IBGBugReporting.floatingButtonTopOffset = [offset doubleValue];
}
- (void)setVideoRecordingFloatingButtonPositionPosition:(NSString *)position error:(FlutterError *_Nullable *_Nonnull)error {
IBGPosition resolvedPosition = (ArgsRegistry.recordButtonPositions[position]).integerValue;
IBGBugReporting.videoRecordingFloatingButtonPosition = resolvedPosition;
}
- (void)setShakingThresholdForiPhoneThreshold:(NSNumber *)threshold error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReporting.shakingThresholdForiPhone = [threshold doubleValue];
}
- (void)setShakingThresholdForiPadThreshold:(NSNumber *)threshold error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReporting.shakingThresholdForiPad = [threshold doubleValue];
}
- (void)setShakingThresholdForAndroidThreshold:(NSNumber *)threshold error:(FlutterError *_Nullable *_Nonnull)error {
// Android Only
}
- (void)setEnabledAttachmentTypesScreenshot:(NSNumber *)screenshot extraScreenshot:(NSNumber *)extraScreenshot galleryImage:(NSNumber *)galleryImage screenRecording:(NSNumber *)screenRecording error:(FlutterError *_Nullable *_Nonnull)error {
IBGAttachmentType resolvedTypes = 0;
if ([screenshot boolValue]) {
resolvedTypes |= IBGAttachmentTypeScreenShot;
}
if ([extraScreenshot boolValue]) {
resolvedTypes |= IBGAttachmentTypeExtraScreenShot;
}
if ([galleryImage boolValue]) {
resolvedTypes |= IBGAttachmentTypeGalleryImage;
}
if ([screenRecording boolValue]) {
resolvedTypes |= IBGAttachmentTypeScreenRecording;
}
IBGBugReporting.enabledAttachmentTypes = resolvedTypes;
}
- (void)bindOnInvokeCallbackWithError:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReporting.willInvokeHandler = ^{
[self->_flutterApi onSdkInvokeWithCompletion:^(FlutterError *_Nullable _){
}];
};
}
- (void)bindOnDismissCallbackWithError:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReporting.didDismissHandler = ^(IBGDismissType dismissType, IBGReportType reportType) {
// Parse dismiss type enum
NSString *dismissTypeString;
if (dismissType == IBGDismissTypeCancel) {
dismissTypeString = @"CANCEL";
} else if (dismissType == IBGDismissTypeSubmit) {
dismissTypeString = @"SUBMIT";
} else if (dismissType == IBGDismissTypeAddAttachment) {
dismissTypeString = @"ADD_ATTACHMENT";
}
// Parse report type enum
NSString *reportTypeString;
if (reportType == IBGReportTypeBug) {
reportTypeString = @"BUG";
} else if (reportType == IBGReportTypeFeedback) {
reportTypeString = @"FEEDBACK";
} else {
reportTypeString = @"OTHER";
}
[self->_flutterApi onSdkDismissDismissType:dismissTypeString
reportType:reportTypeString
completion:^(FlutterError *_Nullable _){
}];
};
}
- (void)setDisclaimerTextText:(NSString *)text error:(FlutterError *_Nullable *_Nonnull)error {
[IBGBugReporting setDisclaimerText:text];
}
- (void)setCommentMinimumCharacterCountLimit:(NSNumber *)limit reportTypes:(nullable NSArray<NSString *> *)reportTypes error:(FlutterError *_Nullable *_Nonnull)error {
IBGBugReportingReportType resolvedTypes = 0;
if (![reportTypes count]) {
resolvedTypes = (ArgsRegistry.reportTypes[@"ReportType.bug"]).integerValue | (ArgsRegistry.reportTypes[@"ReportType.feedback"]).integerValue | (ArgsRegistry.reportTypes[@"ReportType.question"]).integerValue;
}
else {
for (NSString *reportType in reportTypes) {
resolvedTypes |= (ArgsRegistry.reportTypes[reportType]).integerValue;
}
}
[IBGBugReporting setCommentMinimumCharacterCountForReportTypes:resolvedTypes withLimit:limit.intValue];
}
- (void)addUserConsentsKey:(NSString *)key
description:(NSString *)description
mandatory:(NSNumber *)mandatory
checked:(NSNumber *)checked
actionType:(nullable NSString *)actionType
error:(FlutterError *_Nullable *_Nonnull)error {
IBGActionType mappedActionType = (ArgsRegistry.userConsentActionTypes[actionType]).integerValue;
[IBGBugReporting addUserConsentWithKey:key
description:description
mandatory:[mandatory boolValue]
checked:[checked boolValue]
actionType:mappedActionType];
}
@end