Skip to content

Commit 2ab9772

Browse files
authored
Merge pull request #605 from OneSignal/removeDefault
[User Model] Remove OneSignal.Default
2 parents 03b0f37 + 0164cd5 commit 2ab9772

24 files changed

+448
-223
lines changed

MIGRATION_GUIDE_v3_to_v5.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,38 @@ OneSignal uses a built-in **alias label** called `external_id` which supports ex
3131

3232
The OneSignal SDK has been updated to be more modular in nature. The SDK has been split into namespaces and functionality previously in the static `OneSignal.Default` class has been moved to the appropriate namespace. The namespaces, their containing modules, and how to access them in code are as follows:
3333

34-
| Namespace | C# |
35-
| -------------- | -----------------------------------|
36-
| User | `OneSignal.Default.User` |
37-
| Session | `OneSignal.Default.Session` |
38-
| Notifications | `OneSignal.Default.Notifications` |
39-
| Location | `OneSignal.Default.Location` |
40-
| InAppMessages | `OneSignal.Default.InAppMessages` |
41-
| LiveActivities | `OneSignal.Default.LiveActivities` |
42-
| Debug | `OneSignal.Default.Debug` |
34+
| Namespace | C# |
35+
| -------------- | ---------------------------|
36+
| User | `OneSignal.User` |
37+
| Session | `OneSignal.Session` |
38+
| Notifications | `OneSignal.Notifications` |
39+
| Location | `OneSignal.Location` |
40+
| InAppMessages | `OneSignal.InAppMessages` |
41+
| LiveActivities | `OneSignal.LiveActivities` |
42+
| Debug | `OneSignal.Debug` |
4343

4444

4545

4646
## Initialization
4747

4848
Initialization of the OneSignal SDK, although similar to past versions, has changed. The target OneSignal application (`appId`) is now provided as part of initialization and cannot be changed post-initialization. A typical initialization now looks similar to below
4949

50-
OneSignal.Default.Initialize(ONESIGNAL_APP_ID);
50+
OneSignal.Initialize(ONESIGNAL_APP_ID);
5151
// RequestPermissionAsync will show the native platform notification permission prompt.
5252
// We recommend removing the following code and instead using an In-App Message to prompt for notification permission.
53-
var result = await OneSignal.Default.Notifications.RequestPermissionAsync(true);
53+
var result = await OneSignal.Notifications.RequestPermissionAsync(true);
5454

5555
If your integration is not user-centric, there is no additional startup code required. A user is automatically created as part of the push subscription creation, both of which are only accessible from the current device and the OneSignal dashboard.
5656

5757
If your integration is user-centric, or you want the ability to identify as the same user on multiple devices, the OneSignal SDK should be called once the user has been identified:
5858

59-
OneSignal.Default.Login("USER_EXTERNAL_ID");
59+
OneSignal.Login("USER_EXTERNAL_ID");
6060

6161
The `login` method will associate the device’s push subscription to the user that can be identified via alias `externalId=USER_EXTERNAL_ID`. If a user with the provided `externalId` does not exist, one will be created. If a user does already exist, the user will be updated to include the current device’s push subscription. Note that a device's push subscription will always be transferred to the currently logged in user, as they represent the current owners of that push subscription.
6262

6363
Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the OneSignal SDK should be called:
6464

65-
OneSignal.Default.Logout();
65+
OneSignal.Logout();
6666

6767
Logging out has the affect of reverting to a “device-scoped” user, which is the new owner of the device’s push subscription.
6868

@@ -74,7 +74,7 @@ In previous versions of the SDK there was a player that could have zero or one e
7474
**Push Subscription**
7575
The current device’s push subscription can be retrieved via:
7676

77-
var pushSubscription = OneSignal.Default.User.PushSubscription;
77+
var pushSubscription = OneSignal.User.PushSubscription;
7878

7979

8080
If at any point you want the user to stop receiving push notifications on the current device (regardless of permission status) you can use the push subscription to opt out:
@@ -91,14 +91,14 @@ To resume receiving of push notifications (driving the native permission prompt
9191
Email and/or SMS subscriptions can be added or removed via:
9292

9393
// Add email subscription
94-
OneSignal.Default.User.AddEmail("[email protected]")
94+
OneSignal.User.AddEmail("[email protected]")
9595
// Remove previously added email subscription
96-
OneSignal.Default.User.RemoveEmail("[email protected]")
96+
OneSignal.User.RemoveEmail("[email protected]")
9797

9898
// Add SMS subscription
99-
OneSignal.Default.User.AddSms("+15558675309")
99+
OneSignal.User.AddSms("+15558675309")
100100
// Remove previously added SMS subscription
101-
OneSignal.Default.User.RemoveSms("+15558675309")
101+
OneSignal.User.RemoveSms("+15558675309")
102102

103103

104104

@@ -107,7 +107,7 @@ Email and/or SMS subscriptions can be added or removed via:
107107
Below is a comprehensive reference to the v5.0.0 OneSignal SDK.
108108

109109
**OneSignal**
110-
The SDK is still accessible via a `OneSignal.Default` static class, it provides access to higher level functionality and is a gateway to each subspace of the SDK.
110+
The SDK is still accessible via a `OneSignal` static class, it provides access to higher level functionality and is a gateway to each subspace of the SDK.
111111

112112
| **C#** | **Description** |
113113
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -120,7 +120,7 @@ The SDK is still accessible via a `OneSignal.Default` static class, it provides
120120

121121

122122
**User Namespace**
123-
The user name space is accessible via `OneSignal.Default.User` and provides access to user-scoped functionality.
123+
The user name space is accessible via `OneSignal.User` and provides access to user-scoped functionality.
124124

125125
| **C#** | **Description** |
126126
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -142,7 +142,7 @@ The user name space is accessible via `OneSignal.Default.User` and provides acce
142142

143143

144144
**Session Namespace**
145-
The session namespace is accessible via `OneSignal.Default.Session` and provides access to session-scoped functionality.
145+
The session namespace is accessible via `OneSignal.Session` and provides access to session-scoped functionality.
146146

147147
| **C#** | **Description** |
148148
| ---------------------------------------------------- | ---------------------------------------------------------------------------------------- |
@@ -152,11 +152,12 @@ The session namespace is accessible via `OneSignal.Default.Session` and provides
152152

153153

154154
**Notifications Namespace**
155-
The notification namespace is accessible via `OneSignal.Default.Notifications` and provides access to notification-scoped functionality.
155+
The notification namespace is accessible via `OneSignal.Notifications` and provides access to notification-scoped functionality.
156156

157-
| **C#** | **Description** |
158-
| -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
157+
| **C#** | **Description** |
158+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
159159
| `bool Permission` | *Whether this app has push notification permission.* |
160+
| `bool CanRequestPermission` | *Whether this app can request push notification permission.* |
160161
| `NotificationPermission PermissionNative` | *Native permission of the device. The enum NotificationPermission can be NotDetermined, Denied, Authorized, Provisional, or Ephemeral.* |
161162
| `Task<bool> RequestPermissionAsync(bool fallbackToSettings)` | *Prompt the user for permission to push notifications. This will display the native OS prompt to request push notification permission. If the user enables, a push subscription to this device will be automatically added to the user.* |
162163
| `void ClearAllNotifications()` | *Removes all OneSignal notifications.* |
@@ -166,7 +167,7 @@ The notification namespace is accessible via `OneSignal.Default.Notifications` a
166167

167168

168169
**Location Namespace**
169-
The location namespace is accessible via `OneSignal.Default.Location` and provides access to location-scoped functionality.
170+
The location namespace is accessible via `OneSignal.Location` and provides access to location-scoped functionality.
170171

171172
| **C#** | **Description** |
172173
| ---------------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -175,7 +176,7 @@ The location namespace is accessible via `OneSignal.Default.Location` and provid
175176

176177

177178
**InAppMessages Namespace**
178-
The In App Messages namespace is accessible via `OneSignal.Default.InAppMessages` and provides access to in app messages-scoped functionality.
179+
The In App Messages namespace is accessible via `OneSignal.InAppMessages` and provides access to in app messages-scoped functionality.
179180

180181
| **C#** | **Description** |
181182
| ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -190,7 +191,7 @@ The In App Messages namespace is accessible via `OneSignal.Default.InAppMessages
190191

191192

192193
**LiveActivities Namespace**
193-
The Live Activities namespace is accessible via `OneSignal.Default.LiveActivities` and provides access to live activities-scoped functionality.
194+
The Live Activities namespace is accessible via `OneSignal.LiveActivities` and provides access to live activities-scoped functionality.
194195

195196
| **C#** | **Description** |
196197
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -199,7 +200,7 @@ The Live Activities namespace is accessible via `OneSignal.Default.LiveActivitie
199200

200201

201202
**Debug Namespace**
202-
The debug namespace is accessible via `OneSignal.Default.Debug` and provides access to debug-scoped functionality.
203+
The debug namespace is accessible via `OneSignal.Debug` and provides access to debug-scoped functionality.
203204

204205
| **C#** | **Description** |
205206
| --------------------- | -------------------------------------------------------------------------------------------------- |

OneSignalExample/Assets/OneSignal/Attribution/OneSignalVSAttribution.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ namespace OneSignalSDK
3333
internal static class AttachToInit {
3434
#if ONE_SIGNAL_INSTALLED
3535
[RuntimeInitializeOnLoadMethod] public static void Init() {
36-
if (string.IsNullOrEmpty(OneSignal.AppId))
37-
OneSignal.OnInitialize += appId => VSAttribution.SendAttributionEvent("Login", "OneSignal", appId);
36+
if (string.IsNullOrEmpty(OneSignalPlatform.AppId))
37+
OneSignalPlatform.OnInitialize += appId => VSAttribution.SendAttributionEvent("Login", "OneSignal", appId);
3838
else
39-
VSAttribution.SendAttributionEvent("Login", "OneSignal", OneSignal.AppId);
39+
VSAttribution.SendAttributionEvent("Login", "OneSignal", OneSignalPlatform.AppId);
4040
}
4141
#endif
4242
}

0 commit comments

Comments
 (0)