Skip to content

Commit 496a513

Browse files
committed
Updated Android SDK to 3.12.2
* Changed iOS stubs to WARN logs * Added checks for OutcomeEvent so it does not crash when parsing null or null attributes
1 parent 6e920f9 commit 496a513

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ android {
3434
}
3535

3636
dependencies {
37-
api 'com.onesignal:OneSignal:3.12.1'
37+
api 'com.onesignal:OneSignal:3.12.2'
3838
}
3939

4040
// Adds required manifestPlaceholders keys to allow mainifest merge gradle step to complete

android/src/main/java/com/onesignal/flutter/OneSignalOutcomeEventsController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.onesignal.flutter;
22

3+
import androidx.annotation.Nullable;
4+
35
import com.onesignal.OneSignal;
46
import com.onesignal.OutcomeEvent;
57

8+
import java.util.HashMap;
69
import java.util.concurrent.atomic.AtomicBoolean;
710

811
import io.flutter.plugin.common.MethodCall;
@@ -27,12 +30,16 @@ class OSFlutterOutcomeEventsHandler extends FlutterRegistrarResponder implements
2730
}
2831

2932
@Override
30-
public void onSuccess(OutcomeEvent outcomeEvent) {
33+
public void onSuccess(@Nullable OutcomeEvent outcomeEvent) {
3134
if (this.replySubmitted.getAndSet(true))
3235
return;
3336

34-
replySuccess(result, OneSignalSerializer.convertOutcomeEventToMap(outcomeEvent));
37+
if (outcomeEvent == null)
38+
replySuccess(result, new HashMap<>());
39+
else
40+
replySuccess(result, OneSignalSerializer.convertOutcomeEventToMap(outcomeEvent));
3541
}
42+
3643
}
3744

3845
public class OneSignalOutcomeEventsController extends FlutterRegistrarResponder implements MethodCallHandler {

android/src/main/java/com/onesignal/flutter/OneSignalSerializer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ static HashMap<String, Object> convertOutcomeEventToMap(OutcomeEvent outcomeEven
201201
HashMap<String, Object> hash = new HashMap<>();
202202

203203
hash.put("session", outcomeEvent.getSession().toString());
204-
hash.put("notification_ids", outcomeEvent.getNotificationIds().toString());
204+
205+
if (outcomeEvent.getNotificationIds() == null)
206+
hash.put("notification_ids", new JSONArray().toString());
207+
else
208+
hash.put("notification_ids", outcomeEvent.getNotificationIds().toString());
209+
205210
hash.put("id", outcomeEvent.getName());
206211
hash.put("timestamp", outcomeEvent.getTimestamp());
207212
hash.put("weight", String.valueOf(outcomeEvent.getWeight()));

example/lib/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ class _MyAppState extends State<MyApp> {
269269
}
270270

271271
oneSignalOutcomeEventsExamples() async {
272+
// Await example for sending outcomes
273+
outcomeAwaitExample();
274+
272275
// Send a normal outcome and get a reply with the name of the outcome
273276
OneSignal.shared.sendOutcome("normal_1");
274277
OneSignal.shared.sendOutcome("normal_2").then((outcomeEvent) {
@@ -291,6 +294,11 @@ class _MyAppState extends State<MyApp> {
291294
});
292295
}
293296

297+
Future<void> outcomeAwaitExample() async {
298+
var outcomeEvent = await OneSignal.shared.sendOutcome("await_normal_1");
299+
print(outcomeEvent.jsonRepresentation());
300+
}
301+
294302
@override
295303
Widget build(BuildContext context) {
296304
return new MaterialApp(

ios/Classes/OneSignalOutcomeEventsController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
5454

5555
- (void)sendOutcome:(FlutterMethodCall *)call withResult:(FlutterResult)result {
5656
// NSString *name = call.arguments;
57-
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Method sendOutcome() not implemented for iOS yet!"];
57+
[OneSignal onesignal_Log:ONE_S_LL_WARN message:@"Method sendOutcome() not implemented for iOS yet!"];
5858
result(@{});
5959
}
6060

6161
- (void)sendUniqueOutcome:(FlutterMethodCall *)call withResult:(FlutterResult)result {
6262
// NSString *name = call.arguments;
63-
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Method sendUniqueOutcome() not implemented for iOS yet!"];
63+
[OneSignal onesignal_Log:ONE_S_LL_WARN message:@"Method sendUniqueOutcome() not implemented for iOS yet!"];
6464
result(@{});
6565
}
6666

6767
- (void)sendOutcomeWithValue:(FlutterMethodCall *)call withResult:(FlutterResult)result {
6868
// NSString *name = call.arguments[@"outcome_name"];
6969
// NSNumber *value = call.arguments[@"outcome_value"];
70-
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Method sendOutcomeWithValue() not implemented for iOS yet!"];
70+
[OneSignal onesignal_Log:ONE_S_LL_WARN message:@"Method sendOutcomeWithValue() not implemented for iOS yet!"];
7171
result(@{});
7272
}
7373

0 commit comments

Comments
 (0)