Skip to content

Commit 49480f0

Browse files
committed
Add PushSubscriptionObserver methods to the migration guide
1 parent e5a748c commit 49480f0

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

MIGRATION_GUIDE.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ To resume receiving of push notifications (driving the native permission prompt
149149

150150
pushSubscription.optIn()
151151

152+
To observe changes to the push subscription a class can implement the IPushSubscriptionObserver interface, and can then be added as an observer:
153+
154+
**Java**
155+
156+
@Override
157+
public void onPushSubscriptionChange(@NonNull PushSubscriptionChangedState state) {
158+
...
159+
}
160+
161+
pushSubscription.addObserver(this);
162+
163+
**Kotlin**
164+
165+
override fun onPushSubscriptionChange(state: PushSubscriptionChangedState) {
166+
...
167+
}
168+
169+
pushSubscription.addObserver(this)
170+
171+
If you would like to stop observing the subscription you can remove the observer:
172+
173+
**Java**
174+
175+
pushSubscription.removeObserver(this);
176+
177+
**Kotlin**
178+
179+
pushSubscription.removeObserver(this)
152180

153181
**Email/SMS Subscriptions**
154182
Email and/or SMS subscriptions can be added or removed via:
@@ -186,12 +214,12 @@ The OneSignal SDK has been rewritten in Kotlin. This is typically transparent to
186214
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:
187215

188216

189-
OneSignal.getNotifications().requestPermission(Continue.none());
217+
OneSignal.getNotifications().requestPermission(true, Continue.none());
190218

191219
`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:
192220

193221

194-
OneSignal.getNotifications().requestPermission(Continue.with(r -> {
222+
OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
195223
if (r.isSuccess()) {
196224
if (r.getData()) {
197225
// code to execute once requestPermission has completed successfully and the user has accepted permission.

0 commit comments

Comments
 (0)