Skip to content

Commit 95e72b9

Browse files
committed
remove shared from OneSignal and make methods static
everything on the shared instance of OneSignal should now be called on the static OneSignal namespace.
1 parent 6f9eac6 commit 95e72b9

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

example/lib/main.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class _MyAppState extends State<MyApp> {
3535
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
3636

3737
OneSignal.Debug.setAlertLevel(OSLogLevel.none);
38-
OneSignal.shared.consentRequired(_requireConsent);
38+
OneSignal.consentRequired(_requireConsent);
3939

4040
// NOTE: Replace with your own app ID from https://www.onesignal.com
41-
OneSignal.shared.initialize("77e32082-ea27-42e3-a898-c72e141824ef");
41+
OneSignal.initialize("0ba9731b-33bd-43f4-8b59-61172e27447d");
4242

4343
// AndroidOnly stat only
4444
// OneSignal.Notifications.removeNotification(1);
@@ -103,7 +103,7 @@ class _MyAppState extends State<MyApp> {
103103
});
104104

105105
// iOS-only method to open launch URLs in Safari when set to false
106-
OneSignal.shared.setLaunchURLsInApp(false);
106+
OneSignal.setLaunchURLsInApp(false);
107107

108108
this.setState(() {
109109
_enableConsentButton = _requireConsent;
@@ -176,7 +176,7 @@ class _MyAppState extends State<MyApp> {
176176

177177
void _handleConsent() {
178178
print("Setting consent to true");
179-
OneSignal.shared.consentGiven(true);
179+
OneSignal.consentGiven(true);
180180

181181
print("Setting state");
182182
this.setState(() {
@@ -192,12 +192,12 @@ class _MyAppState extends State<MyApp> {
192192
void _handleLogin() {
193193
print("Setting external user ID");
194194
if (_externalUserId == null) return;
195-
OneSignal.shared.login(_externalUserId!);
195+
OneSignal.login(_externalUserId!);
196196
OneSignal.User.addAlias("fb_id", "1341524");
197197
}
198198

199199
void _handleLogout() {
200-
OneSignal.shared.logout();
200+
OneSignal.logout();
201201
OneSignal.User.removeAlias("fb_id");
202202
}
203203

lib/onesignal_flutter.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class OneSignal {
2323
/// Note that the iOS and Android native libraries are static,
2424
/// so if you create multiple instances of OneSignal, they will
2525
/// mostly share the same state.
26-
static OneSignal shared = new OneSignal();
2726
static OneSignalDebug Debug = new OneSignalDebug();
2827
static OneSignalUser User = new OneSignalUser();
2928
static OneSignalNotifications Notifications = new OneSignalNotifications();
@@ -33,13 +32,13 @@ class OneSignal {
3332
static OneSignalLiveActivities LiveActivities = new OneSignalLiveActivities();
3433

3534
// private channels used to bridge to ObjC/Java
36-
MethodChannel _channel = const MethodChannel('OneSignal');
35+
static MethodChannel _channel = const MethodChannel('OneSignal');
3736

3837
/// The initializer for OneSignal.
3938
///
4039
/// The initializer accepts an [appId] which the developer can get
4140
/// from the OneSignal consoleas well as a dictonary of [launchOptions]
42-
void initialize(String appId) {
41+
static void initialize(String appId) {
4342
_channel.invokeMethod('OneSignal#initialize', {'appId': appId});
4443
InAppMessages.lifecycleInit();
4544
User.pushSubscription.lifecycleInit();
@@ -50,7 +49,7 @@ class OneSignal {
5049
///
5150
/// The act of logging a user into the OneSignal SDK will switch the
5251
/// user context to that specific user.
53-
Future<void> login(String externalId) async {
52+
static Future<void> login(String externalId) async {
5453
return await _channel
5554
.invokeMethod('OneSignal#login', {'externalId': externalId});
5655
}
@@ -59,7 +58,7 @@ class OneSignal {
5958
///
6059
/// The act of logging a user into the OneSignal SDK will switch the
6160
/// user context to that specific user.
62-
Future<void> loginWithJWT(String externalId, String jwt) async {
61+
static Future<void> loginWithJWT(String externalId, String jwt) async {
6362
if (Platform.isAndroid) {
6463
return await _channel.invokeMethod(
6564
'OneSignal#loginWithJWT', {'externalId': externalId, 'jwt': jwt});
@@ -71,23 +70,23 @@ class OneSignal {
7170
/// references a new device-scoped user. A device-scoped user has no user identity
7271
/// that can later be retrieved, except through this device as long as the app
7372
/// remains installed and the app data is not cleared.
74-
Future<void> logout() async {
73+
static Future<void> logout() async {
7574
return await _channel.invokeMethod('OneSignal#logout');
7675
}
7776

7877
/// Sets the whether or not privacy consent has been [granted]
7978
///
8079
/// This field is only relevant when the application has
8180
/// opted into data privacy protections. See [consentRequired].
82-
Future<void> consentGiven(bool granted) async {
81+
static Future<void> consentGiven(bool granted) async {
8382
return await _channel
8483
.invokeMethod("OneSignal#consentGiven", {'granted': granted});
8584
}
8685

8786
/// Allows you to completely disable the SDK until your app calls the
8887
/// OneSignal.consentGiven(true) function. This is useful if you want
8988
/// to show a Terms and Conditions or privacy popup for GDPR.
90-
Future<void> consentRequired(bool require) async {
89+
static Future<void> consentRequired(bool require) async {
9190
return await _channel
9291
.invokeMethod("OneSignal#consentRequired", {'required': require});
9392
}
@@ -96,7 +95,7 @@ class OneSignal {
9695
/// within the application. Set to true to launch all notifications with a URL
9796
/// in the app instead of the default web browser. Make sure to call setLaunchURLsInApp
9897
/// before the initialize call.
99-
Future<void> setLaunchURLsInApp(bool launchUrlsInApp) async {
98+
static Future<void> setLaunchURLsInApp(bool launchUrlsInApp) async {
10099
if (Platform.isIOS) {
101100
return await _channel.invokeMethod(
102101
'OneSignal#setLaunchURLsInApp', {'launchUrlsInApp': launchUrlsInApp});

0 commit comments

Comments
 (0)