Skip to content

Commit d611cd2

Browse files
authored
Merge pull request #2347 from OneSignal/docs/update_migration_guide_point_at_docs
2 parents 44508d2 + ee27ced commit d611cd2

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

MIGRATION_GUIDE.md

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,24 @@ OneSignal uses a built-in **alias label** called `external_id` which supports ex
3030

3131
In Android Studio, open your `build.gradle.kts (Module: app)` or `build.gradle (Module: app)` file and update OneSignal in your `dependencies`.
3232

33-
<CodeGroup>
34-
```kotlin app/build.gradle.kts
35-
implementation("com.onesignal:OneSignal:[5.1.6, 5.1.99]")
36-
```
33+
```kotlin
34+
// in app/build.gradle.kts
3735

38-
```groovy app/build.gradle
39-
implementation 'com.onesignal:OneSignal:[5.1.6, 5.1.99]'
40-
```
41-
</CodeGroup>
36+
implementation("com.onesignal:OneSignal:[5.1.6, 5.1.99]")
37+
```
38+
39+
```groovy
40+
// in app/build.gradle
41+
42+
implementation 'com.onesignal:OneSignal:[5.1.6, 5.1.99]'
43+
```
4244

4345
The above statement will bring in the entire OneSignalSDK and is the desired state for most integrations. For greater flexibility you can alternatively specify individual modules that make up the full SDK. The possible modules are:
4446

45-
`com.onesignal:core`: The required core module provided by the OneSignal SDK, this must be included.
46-
`com.onesignal:notifications:` Include to bring in notification based functionality.
47-
`com.onesignal:in-app-messages`: Include to bring in in app message functionality.
48-
`com.onesignal:location`: Include to bring in location-based functionality.
47+
- `com.onesignal:core`: The required core module provided by the OneSignal SDK, this must be included.
48+
- `com.onesignal:notifications`: Include to bring in notification based functionality.
49+
- `com.onesignal:in-app-messages`: Include to bring in in app message functionality.
50+
- `com.onesignal:location`: Include to bring in location-based functionality.
4951

5052

5153
## Code Modularization
@@ -71,8 +73,9 @@ In your `ApplicationClass`, initialize OneSignal with the provided methods.
7173

7274
Replace `YOUR_APP_ID` with your OneSignal App ID found **Settings > [Keys & IDs](https://documentation.onesignal.com/docs/keys-and-ids)** in your OneSignal dashboard. If you don't have access to the OneSignal app, ask your [Team Members](https://documentation.onesignal.com/docs/manage-team-members) to invite you.
7375

74-
<CodeGroup>
75-
```java Kotlin
76+
**Kotlin**
77+
78+
```kotlin
7679
package com.your.package.name // Replace with your package name
7780

7881
import android.app.Application
@@ -101,7 +104,9 @@ class ApplicationClass : Application() {
101104

102105
```
103106

104-
```java Java
107+
**Java**
108+
109+
```java
105110
package com.your.package.name // Replace with your package name
106111

107112
import android.app.Application;
@@ -127,15 +132,14 @@ public class ApplicationClass extends Application {
127132
}
128133

129134
```
130-
</CodeGroup>
131135

132136
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.
133137

134-
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: [`OneSignal.login("USER_EXTERNAL_ID");`](https://documentation.onesignal.com/docs/mobile-sdk-reference#login-external-id)
138+
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: [`OneSignal.login("USER_EXTERNAL_ID")`](https://documentation.onesignal.com/docs/mobile-sdk-reference#login-external-id)
135139

136140
The `login` method will associate the device’s push subscription to the user that can be identified via alias `external_id`. If a user with the provided `external_id` 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.
137141

138-
Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the OneSignal SDK should be called: [`OneSignal.logout();`](https://documentation.onesignal.com/docs/mobile-sdk-reference#logout)
142+
Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the OneSignal SDK should be called: [`OneSignal.logout()`](https://documentation.onesignal.com/docs/mobile-sdk-reference#logout)
139143

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

@@ -145,20 +149,22 @@ Logging out has the affect of reverting to a “device-scoped” user, which is
145149
In previous versions of the SDK there was a player that could have zero or one email address, and zero or one phone number for SMS. In the user-centered model there is a user with the current device’s **Push Subscription** along with the ability to have zero or **more** email subscriptions and zero or **more** SMS subscriptions. A user can also have zero or more push subscriptions, one push subscription for each device the user is logged into via the OneSignal SDK.
146150

147151
**Push Subscription**
152+
148153
The current device’s push subscription can be retrieved via: [`OneSignal.User.pushSubscription`](https://documentation.onesignal.com/docs/mobile-sdk-reference#user-pushsubscription-id)
149154

150155

151-
If at any point you want the user to stop receiving push notifications on the current device (regardless of Android permission status) you can use the push subscription to opt out: [`OneSignal.User.pushSubscription.optOut();`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
156+
If at any point you want the user to stop receiving push notifications on the current device (regardless of Android permission status) you can use the push subscription to opt out: [`OneSignal.User.pushSubscription.optOut()`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
152157

153158

154-
To resume receiving of push notifications (driving the native permission prompt if OS permissions are not available), you can opt back in: [`OneSignal.User.pushSubscription.optIn();`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
159+
To resume receiving of push notifications (driving the native permission prompt if OS permissions are not available), you can opt back in: [`OneSignal.User.pushSubscription.optIn()`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
155160

156161

157-
To observe changes to the push subscription a class can implement the IPushSubscriptionObserver interface, and can then be added as an observer: [`OneSignal.User.pushSubscription.addObserver(observer);`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addobserver-push-subscription-changes)
162+
To observe changes to the push subscription a class can implement the IPushSubscriptionObserver interface, and can then be added as an observer: [`OneSignal.User.pushSubscription.addObserver(observer)`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addobserver-push-subscription-changes)
158163

159164

160165
**Email/SMS Subscriptions**
161-
Email and/or SMS subscriptions can be added or removed via: [`OneSignal.User.addEmail("customer@company.com");`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addemail-email) or [`OneSignal.User.addSms("+15558675309");`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addsms-sms)
166+
167+
Email and/or SMS subscriptions can be added or removed via: [`OneSignal.User.addEmail("customer@company.com")`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addemail-email) or [`OneSignal.User.addSms("+15558675309")`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addsms-sms)
162168

163169

164170
## Kotlin-Related Changes
@@ -167,25 +173,25 @@ The OneSignal SDK has been rewritten in Kotlin. This is typically transparent to
167173

168174
In Java this is surfaced on a method via an additional parameter to the method of type `Continuation`. The `Continuation` is a callback mechanism which allows a Java function to gain control when execution has resumed. If this concept is newer to your application codebase, OneSignal provides an optional java helper class to facilitate the callback model. Method `com.onesignal.Continue.none()` can be used to indicate no callback is necessary:
169175

170-
171-
OneSignal.getNotifications().requestPermission(true, Continue.none());
172-
176+
```java
177+
OneSignal.getNotifications().requestPermission(true, Continue.none());
178+
```
173179
`com.onesignal.Continue.with()` can be used to create a callback lambda expression, which is passed a `ContinueResult` containing information on the success of the underlying coroutine, it's return data, and/or the exception that was thrown:
174180

175-
```
176-
OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
177-
if (r.isSuccess()) {
178-
if (r.getData()) {
179-
// code to execute once requestPermission has completed successfully and the user has accepted permission.
180-
}
181-
else {
182-
// code to execute once requestPermission has completed successfully but the user has rejected permission.
183-
}
184-
}
185-
else {
186-
// code to execute once requestPermission has completed unsuccessfully, `r.getThrowable()` might have more information as to the reason for failure.
187-
}
188-
}));
181+
```java
182+
OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
183+
if (r.isSuccess()) {
184+
if (r.getData()) {
185+
// code to execute once requestPermission has completed successfully and the user has accepted permission.
186+
}
187+
else {
188+
// code to execute once requestPermission has completed successfully but the user has rejected permission.
189+
}
190+
}
191+
else {
192+
// code to execute once requestPermission has completed unsuccessfully, `r.getThrowable()` might have more information as to the reason for failure.
193+
}
194+
}));
189195
```
190196

191197

0 commit comments

Comments
 (0)