Skip to content

Commit 77a218a

Browse files
committed
Fixes and updates from testing android
1 parent 0a1e142 commit 77a218a

16 files changed

+86
-74
lines changed

android/build.gradle

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

3636
dependencies {
37-
implementation 'com.onesignal:OneSignal:5.0.0-beta1'
37+
implementation 'com.onesignal:OneSignal:5.0.0-beta2'
3838
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class OneSignalInAppMessages extends FlutterRegistrarResponder implements
2424

2525
static void registerWith(BinaryMessenger messenger) {
2626
OneSignalInAppMessages sharedInstance = new OneSignalInAppMessages();
27-
2827
sharedInstance.messenger = messenger;
2928
sharedInstance.channel = new MethodChannel(messenger, "OneSignal#inappmessages");
3029
sharedInstance.channel.setMethodCallHandler(sharedInstance);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ else if (call.method.contentEquals("OneSignal#removeGroupedNotifications"))
6262
else if (call.method.contentEquals("OneSignal#clearAll"))
6363
this.clearAll(call, result);
6464
else if (call.method.contentEquals("OneSignal#initNotificationOpenedHandlerParams"))
65-
this.initNotificationOpenedHandlerParams();
65+
this.initNotificationOpenedHandlerParams(call, result);
6666
else if (call.method.contentEquals("OneSignal#initNotificationWillShowInForegroundHandlerParams"))
6767
this.initNotificationWillShowInForegroundHandlerParams();
6868
else if (call.method.contentEquals("OneSignal#completeNotification"))
69-
this.initNotificationWillShowInForegroundHandlerParams();
69+
this.completeNotification(call, result);
7070
else if (call.method.contentEquals("OneSignal#lifecycleInit"))
7171
this.lifecycleInit();
7272
else
@@ -98,16 +98,17 @@ private void clearAll(MethodCall call, Result result) {
9898
}
9999

100100

101-
private void initNotificationOpenedHandlerParams() {
101+
private void initNotificationOpenedHandlerParams(MethodCall call, Result result) {
102102
OneSignal.getNotifications().setNotificationClickHandler(this);
103+
replySuccess(result, null);
103104
}
104105

105106

106107
private void initNotificationWillShowInForegroundHandlerParams() {
107108
this.hasSetNotificationWillShowInForegroundHandler = true;
108109
}
109110

110-
private void completeNotification(MethodCall call, final Result reply) {
111+
private void completeNotification(MethodCall call, Result result) {
111112
String notificationId = call.argument("notificationId");
112113
boolean shouldDisplay = call.argument("shouldDisplay");
113114
INotificationReceivedEvent notificationReceivedEvent = notificationReceivedEventCache.get(notificationId);
@@ -122,6 +123,7 @@ private void completeNotification(MethodCall call, final Result reply) {
122123
} else {
123124
notificationReceivedEvent.complete(null);
124125
}
126+
replySuccess(result, null);
125127
}
126128

127129
@Override

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.onesignal.OneSignal;
1010
import com.onesignal.Continue;
11+
import com.onesignal.common.OneSignalWrapper;
1112

1213
import org.json.JSONException;
1314
import org.json.JSONObject;
@@ -37,8 +38,10 @@ private void init(Context context, BinaryMessenger messenger)
3738
{
3839
this.context = context;
3940
this.messenger = messenger;
40-
// TODO version
41-
// OneSignal.sdkType = "flutter";
41+
OneSignalWrapper.setSdkType("flutter");
42+
// For 5.0.0-beta, hard code to reflect SDK version
43+
OneSignalWrapper.setSdkVersion("050000");
44+
4245
channel = new MethodChannel(messenger, "OneSignal");
4346
channel.setMethodCallHandler(this);
4447

@@ -116,6 +119,8 @@ else if (call.method.contentEquals("OneSignal#setPrivacyConsent"))
116119
this.setPrivacyConsent(call, result);
117120
else if (call.method.contentEquals("OneSignal#login"))
118121
this.login(call, result);
122+
else if (call.method.contentEquals("OneSignal#loginWithJWT"))
123+
this.loginWithJWT(call, result);
119124
else if (call.method.contentEquals("OneSignal#logout"))
120125
this.logout(call, result);
121126
else
@@ -144,6 +149,11 @@ private void login(MethodCall call, Result result) {
144149
OneSignal.login((String) call.argument("externalId"));
145150
replySuccess(result, null);
146151
}
152+
153+
private void loginWithJWT(MethodCall call, Result result) {
154+
OneSignal.login((String) call.argument("externalId"), (String) call.argument("jwt"));
155+
replySuccess(result, null);
156+
}
147157
private void logout(MethodCall call, Result result) {
148158
OneSignal.logout();
149159
replySuccess(result, null);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.onesignal.user.subscriptions.ISubscription;
77
import com.onesignal.user.subscriptions.ISubscriptionChangedHandler;
88

9+
import com.onesignal.debug.internal.logging.Logging;
10+
911
import org.json.JSONException;
1012
import org.json.JSONObject;
1113

@@ -65,9 +67,9 @@ public void lifecycleInit() {
6567
public void onSubscriptionChanged(ISubscription subscription) {
6668
if (!(subscription instanceof IPushSubscription)){
6769
return;
68-
}
70+
}
6971
IPushSubscription pushSubscription = (IPushSubscription) subscription;
70-
invokeMethodOnUiThread("OneSignal#onSubscriptionChanged", OneSignalSerializer.convertOnSubscriptionChanged(pushSubscription));
72+
invokeMethodOnUiThread("OneSignal#pushSubscriptionChanged", OneSignalSerializer.convertOnSubscriptionChanged(pushSubscription));
7173
}
7274

7375
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ static HashMap<String, Object> convertNotificationToMap(INotification notificati
7171
if (notification.getActionButtons() != null) {
7272
hash.put("actionButtons", notification.getActionButtons());
7373
}
74-
// TODO : rawPayload
75-
// hash.put("rawPayload", notification.getRawPayload());
74+
hash.put("rawPayload", notification.getRawPayload());
7675
return hash;
7776
}
7877

@@ -105,7 +104,7 @@ private static HashMap<String, Object> convertNotificationActionToMap(INotificat
105104
static HashMap<String, Object> convertPermissionChanged(boolean state) {
106105
HashMap<String, Object> permission = new HashMap<>();
107106

108-
permission.put("areNotificationsEnabled", state);
107+
permission.put("permission", state);
109108

110109
return permission;
111110
}
@@ -135,7 +134,7 @@ static HashMap<String, Object> convertOnSubscriptionChanged(IPushSubscription st
135134

136135

137136
hash.put("token", state.getToken());
138-
hash.put("pushId", state.getId());
137+
hash.put("id", state.getId());
139138
hash.put("optedIn", state.getOptedIn());
140139

141140
return hash;

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ target 'Runner' do
3232
end
3333

3434
target 'OneSignalNotificationServiceExtension' do
35-
pod 'OneSignalXCFramework', '5.0.0-beta-01'
35+
pod 'OneSignalXCFramework', '5.0.0-beta-02'
3636
end
3737

3838
post_install do |installer|

example/lib/main.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class MyApp extends StatefulWidget {
1111
_MyAppState createState() => new _MyAppState();
1212
}
1313

14-
class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
14+
class _MyAppState extends State<MyApp>
15+
with OneSignalPushSubscriptionObserver, OneSignalPermissionObserver {
1516
String _debugLabelString = "";
1617
String? _emailAddress;
1718
String? _smsNumber;
@@ -32,14 +33,15 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
3233
Future<void> initPlatformState() async {
3334
if (!mounted) return;
3435

35-
OneSignal.Debug.setLogLevel(OSLogLevel.none);
36+
OneSignal.Debug.setLogLevel(OSLogLevel.debug);
3637

3738
OneSignal.Debug.setAlertLevel(OSLogLevel.none);
3839

3940
// NOTE: Replace with your own app ID from https://www.onesignal.com
4041
OneSignal.shared.initialize("77e32082-ea27-42e3-a898-c72e141824ef");
4142

4243
OneSignal.User.pushSubscription.addObserver(this);
44+
OneSignal.Notifications.addPermssionObserver(this);
4345

4446
OneSignal.shared.setRequiresPrivacyConsent(_requireConsent);
4547

@@ -106,12 +108,15 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
106108
oneSignalOutcomeExamples();
107109
}
108110

109-
void onOSPushSubscriptionChangedWithStateChanges(
110-
OSPushSubscriptionStateChanges stateChanges) {
111-
print(OneSignal.User.pushSubscription.optedIn());
112-
print(OneSignal.User.pushSubscription.id());
113-
print(OneSignal.User.pushSubscription.token());
114-
print(stateChanges.jsonRepresentation());
111+
void onOSPermissionChanged(bool state) {
112+
print("Has permission " + state.toString());
113+
}
114+
115+
void onOSPushSubscriptionChangedWithState(OSPushSubscriptionState state) {
116+
print(OneSignal.User.pushSubscription.optedIn);
117+
print(OneSignal.User.pushSubscription.id);
118+
print(OneSignal.User.pushSubscription.token);
119+
print(state.jsonRepresentation());
115120
}
116121

117122
void _handleSendTags() {

ios/onesignal_flutter.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'onesignal_flutter'
6-
s.version = '5.0.0-beta-01'
6+
s.version = '5.0.0-beta-02'
77
s.summary = 'The OneSignal Flutter SDK'
88
s.description = 'Allows you to easily add OneSignal to your flutter projects, to make sending and handling push notifications easy'
99
s.homepage = 'https://www.onesignal.com'
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
1313
s.source_files = 'Classes/**/*'
1414
s.public_header_files = 'Classes/**/*.h'
1515
s.dependency 'Flutter'
16-
s.dependency 'OneSignalXCFramework', '5.0.0-beta-01'
16+
s.dependency 'OneSignalXCFramework', '5.0.0-beta-02'
1717
s.ios.deployment_target = '11.0'
1818
s.static_framework = true
1919
end

lib/onesignal_flutter.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import 'package:onesignal_flutter/src/session.dart';
88
import 'package:onesignal_flutter/src/location.dart';
99
import 'package:onesignal_flutter/src/inappmessages.dart';
1010

11-
export 'src/permission.dart';
1211
export 'src/defines.dart';
1312
export 'src/pushsubscription.dart';
1413
export 'src/subscription.dart';
1514
export 'src/notification.dart';
15+
export 'src/notifications.dart';
1616
export 'src/inappmessage.dart';
1717

1818
class OneSignal {
@@ -51,6 +51,17 @@ class OneSignal {
5151
.invokeMethod('OneSignal#login', {'externalId': externalId});
5252
}
5353

54+
/// Login to OneSignal under the user identified by the [externalId] provided.
55+
///
56+
/// The act of logging a user into the OneSignal SDK will switch the
57+
/// user context to that specific user.
58+
Future<void> loginWithJWT(String externalId, String jwt) async {
59+
if (Platform.isAndroid) {
60+
return await _channel.invokeMethod(
61+
'OneSignal#loginWithJWT', {'externalId': externalId, 'jwt': jwt});
62+
}
63+
}
64+
5465
/// Logout the user previously logged in via [login]. The [user] property now
5566
///
5667
/// references a new device-scoped user. A device-scoped user has no user identity

0 commit comments

Comments
 (0)