Skip to content

Commit 9baf096

Browse files
via-guyTheBuggedYRN
authored andcommitted
Fix void calls on iOS (#205)
1 parent 614f593 commit 9baf096

File tree

8 files changed

+124
-116
lines changed

8 files changed

+124
-116
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v10.11.1 (2022-02-18)
2+
3+
* Fixes iOS platform calls not completing with `void` return type
4+
15
## v10.11.0 (2022-01-04)
26

37
* Adds support for APM.endAppLaunch API

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ linter:
155155
- throw_in_finally
156156
# - type_annotate_public_apis # subset of always_specify_types
157157
- type_init_formals
158-
# - unawaited_futures # too many false positives
158+
- unawaited_futures
159159
# - unnecessary_await_in_return # not yet tested
160160
- unnecessary_brace_in_string_interps
161161
- unnecessary_const

ios/Classes/InstabugFlutterPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
*
429429
* @param isEnabled whether chat notification is reburied or not
430430
*/
431-
- (void)setChatNotificationEnabled:(NSNumber *)isEnabled;
431+
+ (void)setChatNotificationEnabled:(NSNumber *)isEnabled;
432432

433433
+ (void)networkLog:(NSDictionary *)networkData;
434434

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,40 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
2020

2121
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
2222
BOOL isImplemented = NO;
23-
SEL method = NSSelectorFromString(call.method);
24-
if([[InstabugFlutterPlugin class] respondsToSelector:method]) {
23+
SEL method = NSSelectorFromString(call.method);
24+
if ([[InstabugFlutterPlugin class] respondsToSelector:method]) {
2525
isImplemented = YES;
2626
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[InstabugFlutterPlugin class] methodSignatureForSelector:method]];
2727
[inv setSelector:method];
2828
[inv setTarget:[InstabugFlutterPlugin class]];
2929
/*
3030
* Indices 0 and 1 indicate the hidden arguments self and _cmd,
31-
* respectively; you should set these values directly with the target and selector properties.
31+
* respectively; you should set these values directly with the target and selector properties.
3232
* Use indices 2 and greater for the arguments normally passed in a message.
3333
*/
3434
NSInteger index = 2;
3535
NSArray* argumentsArray = call.arguments;
3636
for (NSObject * argument in argumentsArray) {
37-
[inv setArgument:&(argument) atIndex:index];
38-
index++;
39-
}
37+
[inv setArgument:&argument atIndex:index];
38+
index++;
39+
}
4040
[inv invoke];
41-
NSMethodSignature *signature = [inv methodSignature];
42-
const char *type = [signature methodReturnType];
43-
44-
if (strcmp(type, "v") != 0) {
45-
void *returnVal;
46-
[inv getReturnValue:&returnVal];
47-
NSObject *resultSet = (__bridge NSObject *)returnVal;
48-
result(resultSet);
49-
}
50-
}
41+
NSMethodSignature *signature = [inv methodSignature];
42+
const char *type = [signature methodReturnType];
43+
44+
if (result != nil) {
45+
if (strcmp(type, "v") != 0) {
46+
void *returnVal;
47+
[inv getReturnValue:&returnVal];
48+
NSObject *resultSet = (__bridge NSObject *)returnVal;
49+
result(resultSet);
50+
} else {
51+
result(nil);
52+
}
53+
}
54+
}
5155
if (!isImplemented) {
52-
result(FlutterMethodNotImplemented);
56+
result(FlutterMethodNotImplemented);
5357
}
5458
}
5559

lib/APM.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import 'dart:async';
44
import 'dart:io';
5+
56
import 'package:flutter/services.dart';
67
import 'package:instabug_flutter/models/network_data.dart';
78
import 'package:instabug_flutter/models/trace.dart';
@@ -32,21 +33,21 @@ class APM {
3233

3334
/// Enables or disables APM feature.
3435
/// [boolean] isEnabled
35-
static void setEnabled(bool isEnabled) async {
36+
static Future<void> setEnabled(bool isEnabled) async {
3637
final List<dynamic> params = <dynamic>[isEnabled];
3738
await _channel.invokeMethod<Object>('setAPMEnabled:', params);
3839
}
3940

4041
/// Sets log Level to determine level of details in a log
4142
/// [logLevel] Enum value to determine the level
42-
static void setLogLevel(LogLevel logLevel) async {
43+
static Future<void> setLogLevel(LogLevel logLevel) async {
4344
final List<dynamic> params = <dynamic>[logLevel.toString()];
4445
await _channel.invokeMethod<Object>('setAPMLogLevel:', params);
4546
}
4647

4748
/// Enables or disables cold app launch tracking.
4849
/// [boolean] isEnabled
49-
static void setColdAppLaunchEnabled(bool isEnabled) async {
50+
static Future<void> setColdAppLaunchEnabled(bool isEnabled) async {
5051
final List<dynamic> params = <dynamic>[isEnabled];
5152
await _channel.invokeMethod<Object>('setColdAppLaunchEnabled:', params);
5253
}
@@ -69,15 +70,15 @@ class APM {
6970
}
7071
};
7172
_startExecutionTraceCallback = callback;
72-
_channel.invokeMethod<Object>('startExecutionTrace:id:', params);
73+
await _channel.invokeMethod<Object>('startExecutionTrace:id:', params);
7374
return completer.future;
7475
}
7576

7677
/// Sets attribute of an execution trace.
7778
/// [String] id of the trace.
7879
/// [String] key of attribute.
7980
/// [String] value of attribute.
80-
static void setExecutionTraceAttribute(
81+
static Future<void> setExecutionTraceAttribute(
8182
String id, String key, String value) async {
8283
final List<dynamic> params = <dynamic>[
8384
id.toString(),
@@ -90,27 +91,27 @@ class APM {
9091

9192
/// Ends an execution trace.
9293
/// [String] id of the trace.
93-
static void endExecutionTrace(String id) async {
94+
static Future<void> endExecutionTrace(String id) async {
9495
final List<dynamic> params = <dynamic>[id];
9596
await _channel.invokeMethod<Object>('endExecutionTrace:', params);
9697
}
9798

9899
/// Enables or disables auto UI tracing.
99100
/// [boolean] isEnabled
100-
static void setAutoUITraceEnabled(bool isEnabled) async {
101+
static Future<void> setAutoUITraceEnabled(bool isEnabled) async {
101102
final List<dynamic> params = <dynamic>[isEnabled];
102103
await _channel.invokeMethod<Object>('setAutoUITraceEnabled:', params);
103104
}
104105

105106
/// Starts UI trace.
106107
/// [String] name
107-
static void startUITrace(String name) async {
108+
static Future<void> startUITrace(String name) async {
108109
final List<dynamic> params = <dynamic>[name];
109110
await _channel.invokeMethod<Object>('startUITrace:', params);
110111
}
111112

112113
/// Ends UI trace.
113-
static void endUITrace() async {
114+
static Future<void> endUITrace() async {
114115
await _channel.invokeMethod<Object>('endUITrace');
115116
}
116117
/// Ends UI trace.

lib/CrashReporting.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CrashReporting {
2626

2727
static Future<void> reportCrash(dynamic exception, StackTrace stack) async {
2828
if (kReleaseMode && enabled) {
29-
_reportUnhandledCrash(exception, stack);
29+
await _reportUnhandledCrash(exception, stack);
3030
} else {
3131
FlutterError.dumpErrorToConsole(
3232
FlutterErrorDetails(stack: stack, exception: exception));
@@ -38,12 +38,12 @@ class CrashReporting {
3838
/// [StackTrace] stack
3939
static Future<void> reportHandledCrash(dynamic exception,
4040
[StackTrace? stack]) async {
41-
_sendCrash(exception, stack ?? StackTrace.current, true);
41+
await _sendCrash(exception, stack ?? StackTrace.current, true);
4242
}
4343

4444
static Future<void> _reportUnhandledCrash(
4545
dynamic exception, StackTrace stack) async {
46-
_sendCrash(exception, stack, false);
46+
await _sendCrash(exception, stack, false);
4747
}
4848

4949
static Future<void> _sendCrash(

lib/Instabug.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Instabug {
148148

149149
/// Sets the verbosity level of logs used to debug The SDK. The defualt value in debug
150150
/// mode is sdkDebugLogsLevelVerbose and in production is sdkDebugLogsLevelError.
151-
static void setSdkDebugLogsLevel(
151+
static Future<void> setSdkDebugLogsLevel(
152152
IBGSDKDebugLogsLevel sdkDebugLogsLevel) async {
153153
final List<dynamic> params = <dynamic>[sdkDebugLogsLevel.toString()];
154154
await _channel.invokeMethod<Object>('setSdkDebugLogsLevel:', params);
@@ -238,7 +238,7 @@ class Instabug {
238238
/// Android only
239239
/// Enable/disable SDK logs
240240
/// [debugEnabled] desired state of debug mode.
241-
static void setDebugEnabled(bool debugEnabled) async {
241+
static Future<void> setDebugEnabled(bool debugEnabled) async {
242242
if (PlatformManager.instance.isAndroid()) {
243243
final List<dynamic> params = <dynamic>[debugEnabled];
244244
await _channel.invokeMethod<Object>('setDebugEnabled:', params);

0 commit comments

Comments
 (0)