Skip to content

Commit 5b7fae8

Browse files
committed
Call return handler for void methods on iOS
1 parent 0267e49 commit 5b7fae8

11 files changed

+138
-124
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
## v9.1.8 (2021-02-17)
77

88
* Fixes an issue with iOS invocation events causing the welcome message not to show.
9+
* Change all `void ... async` methods to `Future<void> ... async` so that callers can use `await`.
910

1011
## v9.1.7 (2020-10-01)
1112

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
3939
const char *type = [signature methodReturnType];
4040

4141
if (strcmp(type, "v") != 0) {
42-
void *returnVal;
42+
void *returnVal;
4343
[inv getReturnValue:&returnVal];
4444
NSObject *resultSet = (__bridge NSObject *)returnVal;
4545
result(resultSet);
46+
} else {
47+
result(nil);
4648
}
4749
}
4850
if (!isImplemented) {

lib/BugReporting.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:io' show Platform;
3+
34
import 'package:flutter/services.dart';
45
import 'package:instabug_flutter/Instabug.dart';
56

@@ -74,7 +75,7 @@ class BugReporting {
7475

7576
///Enables and disables manual invocation and prompt options for bug and feedback.
7677
/// [boolean] isEnabled
77-
static void setEnabled(bool isEnabled) async {
78+
static Future<void> setEnabled(bool isEnabled) async {
7879
final List<dynamic> params = <dynamic>[isEnabled];
7980
await _channel.invokeMethod<Object>('setBugReportingEnabled:', params);
8081
}
@@ -83,7 +84,7 @@ class BugReporting {
8384
/// This block is executed on the UI thread. Could be used for performing any
8485
/// UI changes before the SDK's UI is shown.
8586
/// [function] A callback that gets executed before invoking the SDK
86-
static void setOnInvokeCallback(Function function) async {
87+
static Future<void> setOnInvokeCallback(Function function) async {
8788
_channel.setMethodCallHandler(_handleMethod);
8889
_onInvokeCallback = function;
8990
await _channel.invokeMethod<Object>('setOnInvokeCallback');
@@ -93,7 +94,7 @@ class BugReporting {
9394
/// This block is executed on the UI thread. Could be used for performing any
9495
/// UI changes before the SDK's UI is shown.
9596
/// [function] A callback that gets executed before invoking the SDK
96-
static void setOnDismissCallback(Function function) async {
97+
static Future<void> setOnDismissCallback(Function function) async {
9798
_channel.setMethodCallHandler(_handleMethod);
9899
_onDismissCallback = function;
99100
await _channel.invokeMethod<Object>('setOnDismissCallback');
@@ -102,7 +103,7 @@ class BugReporting {
102103
/// Sets the events that invoke the feedback form.
103104
/// Default is set by `Instabug.startWithToken`.
104105
/// [invocationEvents] invocationEvent List of events that invokes the
105-
static void setInvocationEvents(
106+
static Future<void> setInvocationEvents(
106107
List<InvocationEvent> invocationEvents) async {
107108
final List<String> invocationEventsStrings = <String>[];
108109
if (invocationEvents != null) {
@@ -121,8 +122,8 @@ class BugReporting {
121122
/// attachments. In iOS 10+,NSPhotoLibraryUsageDescription should be set in
122123
/// info.plist to enable gallery image attachments.
123124
/// [screenRecording] A boolean to enable or disable screen recording attachments.
124-
static void setEnabledAttachmentTypes(bool screenshot, bool extraScreenshot,
125-
bool galleryImage, bool screenRecording) async {
125+
static Future<void> setEnabledAttachmentTypes(bool screenshot,
126+
bool extraScreenshot, bool galleryImage, bool screenRecording) async {
126127
final List<dynamic> params = <dynamic>[
127128
screenshot,
128129
extraScreenshot,
@@ -136,7 +137,7 @@ class BugReporting {
136137

137138
///Sets what type of reports, bug or feedback, should be invoked.
138139
/// [reportTypes] - List of reportTypes
139-
static void setReportTypes(List<ReportType> reportTypes) async {
140+
static Future<void> setReportTypes(List<ReportType> reportTypes) async {
140141
final List<String> reportTypesStrings = <String>[];
141142
if (reportTypes != null) {
142143
reportTypes.forEach((e) {
@@ -150,7 +151,7 @@ class BugReporting {
150151
/// Sets whether the extended bug report mode should be disabled, enabled with
151152
/// required fields or enabled with optional fields.
152153
/// [extendedBugReportMode] ExtendedBugReportMode enum
153-
static void setExtendedBugReportMode(
154+
static Future<void> setExtendedBugReportMode(
154155
ExtendedBugReportMode extendedBugReportMode) async {
155156
final List<dynamic> params = <dynamic>[extendedBugReportMode.toString()];
156157
await _channel.invokeMethod<Object>('setExtendedBugReportMode:', params);
@@ -159,7 +160,7 @@ class BugReporting {
159160
/// Sets the invocation options.
160161
/// Default is set by `Instabug.startWithToken`.
161162
/// [invocationOptions] List of invocation options
162-
static void setInvocationOptions(
163+
static Future<void> setInvocationOptions(
163164
List<InvocationOption> invocationOptions) async {
164165
final List<String> invocationOptionsStrings = <String>[];
165166
if (invocationOptions != null) {
@@ -174,7 +175,7 @@ class BugReporting {
174175
/// Invoke bug reporting with report type and options.
175176
/// [reportType] type
176177
/// [invocationOptions] List of invocation options
177-
static void show(
178+
static Future<void> show(
178179
ReportType reportType, List<InvocationOption> invocationOptions) async {
179180
final List<String> invocationOptionsStrings = <String>[];
180181
if (invocationOptions != null) {
@@ -193,7 +194,7 @@ class BugReporting {
193194
/// Sets the threshold value of the shake gesture for iPhone/iPod Touch
194195
/// Default for iPhone is 2.5.
195196
/// [iPhoneShakingThreshold] iPhoneShakingThreshold double
196-
static void setShakingThresholdForiPhone(
197+
static Future<void> setShakingThresholdForiPhone(
197198
double iPhoneShakingThreshold) async {
198199
if (Platform.isIOS) {
199200
final List<dynamic> params = <dynamic>[iPhoneShakingThreshold];
@@ -205,7 +206,8 @@ class BugReporting {
205206
/// Sets the threshold value of the shake gesture for iPad
206207
/// Default for iPhone is 0.6.
207208
/// [iPadShakingThreshold] iPhoneShakingThreshold double
208-
static void setShakingThresholdForiPad(double iPadShakingThreshold) async {
209+
static Future<void> setShakingThresholdForiPad(
210+
double iPadShakingThreshold) async {
209211
if (Platform.isIOS) {
210212
final List<dynamic> params = <dynamic>[iPadShakingThreshold];
211213
await _channel.invokeMethod<Object>(
@@ -218,7 +220,8 @@ class BugReporting {
218220
/// you could increase the shaking difficulty level by
219221
/// increasing the `350` value and vice versa
220222
/// [androidThreshold] iPhoneShakingThreshold int
221-
static void setShakingThresholdForAndroid(int androidThreshold) async {
223+
static Future<void> setShakingThresholdForAndroid(
224+
int androidThreshold) async {
222225
if (Platform.isAndroid) {
223226
final List<dynamic> params = <dynamic>[androidThreshold];
224227
await _channel.invokeMethod<Object>(

lib/Chats.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
23
import 'package:flutter/services.dart';
34

45
class Chats {
@@ -8,19 +9,21 @@ class Chats {
89
final String version = await _channel.invokeMethod('getPlatformVersion');
910
return version;
1011
}
11-
12+
1213
@deprecated
14+
1315
///Use {@link BugReporting.show} instead.
1416
///Manual invocation for chats view.
15-
static void show() async {
17+
static Future<void> show() async {
1618
await _channel.invokeMethod<Object>('showChats');
1719
}
1820

1921
@deprecated
22+
2023
///Use {@link BugReporting.setReportTypes} instead.
2124
/// Enables and disables everything related to creating new chats.
2225
/// [boolean] isEnabled
23-
static void setEnabled(bool isEnabled) async {
26+
static Future<void> setEnabled(bool isEnabled) async {
2427
final List<dynamic> params = <dynamic>[isEnabled];
2528
await _channel.invokeMethod<Object>('setChatsEnabled:', params);
2629
}

lib/CrashReporting.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io' show Platform, exit;
4-
import 'package:flutter/services.dart';
4+
55
import 'package:flutter/foundation.dart';
6+
import 'package:flutter/services.dart';
67
import 'package:instabug_flutter/models/crash_data.dart';
78
import 'package:instabug_flutter/models/exception_data.dart';
89
import 'package:stack_trace/stack_trace.dart';
@@ -17,13 +18,13 @@ class CrashReporting {
1718

1819
///Enables and disables Enables and disables automatic crash reporting.
1920
/// [boolean] isEnabled
20-
static void setEnabled(bool isEnabled) async {
21+
static Future<void> setEnabled(bool isEnabled) async {
2122
enabled = isEnabled;
2223
final List<dynamic> params = <dynamic>[isEnabled];
2324
await _channel.invokeMethod<Object>('setCrashReportingEnabled:', params);
2425
}
2526

26-
static void reportCrash(dynamic exception, StackTrace stack) async {
27+
static Future<void> reportCrash(dynamic exception, StackTrace stack) async {
2728
if (kReleaseMode && enabled) {
2829
_reportUnhandledCrash(exception, stack);
2930
} else {
@@ -35,19 +36,21 @@ class CrashReporting {
3536
/// Reports a handled crash to you dashboard
3637
/// [dynamic] exception
3738
/// [StackTrace] stack
38-
static void reportHandledCrash(dynamic exception, [StackTrace stack]) async {
39+
static Future<void> reportHandledCrash(dynamic exception,
40+
[StackTrace stack]) async {
3941
if (stack != null) {
4042
_sendCrash(exception, stack, true);
4143
} else {
4244
_sendCrash(exception, StackTrace.current, true);
4345
}
4446
}
4547

46-
static void _reportUnhandledCrash(dynamic exception, StackTrace stack) async {
48+
static Future<void> _reportUnhandledCrash(
49+
dynamic exception, StackTrace stack) async {
4750
_sendCrash(exception, stack, false);
4851
}
4952

50-
static void _sendCrash(
53+
static Future<void> _sendCrash(
5154
dynamic exception, StackTrace stack, bool handled) async {
5255
final Trace trace = Trace.from(stack);
5356
final List<ExceptionData> frames = <ExceptionData>[];

lib/FeatureRequests.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import 'dart:async';
2+
23
import 'package:flutter/services.dart';
34

4-
enum ActionType {
5-
requestNewFeature,
6-
addCommentToFeature
7-
}
5+
enum ActionType { requestNewFeature, addCommentToFeature }
86

97
class FeatureRequests {
108
static const MethodChannel _channel = MethodChannel('instabug_flutter');
@@ -15,7 +13,7 @@ class FeatureRequests {
1513
}
1614

1715
///Shows the UI for feature requests list
18-
static void show() async {
16+
static Future<void> show() async {
1917
await _channel.invokeMethod<Object>('showFeatureRequests');
2018
}
2119

@@ -24,7 +22,7 @@ class FeatureRequests {
2422
/// [isEmailFieldRequired] A boolean to indicate whether email
2523
/// field is required or not.
2624
/// [actionTypes] An enum that indicates which action types will have the isEmailFieldRequired
27-
static void setEmailFieldRequired(
25+
static Future<void> setEmailFieldRequired(
2826
bool isEmailFieldRequired, List<ActionType> actionTypes) async {
2927
final List<String> actionTypesStrings = <String>[];
3028
if (actionTypes != null) {

0 commit comments

Comments
 (0)