Skip to content

Commit

Permalink
Add getters and observer for oneSignalId and externalId
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed Feb 12, 2024
1 parent 79498b3 commit d57c900
Show file tree
Hide file tree
Showing 19 changed files with 970 additions and 4 deletions.
11 changes: 11 additions & 0 deletions MIGRATION_GUIDE_v3_to_v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ Once (or if) the user is no longer identifiable in your app (i.e. they logged ou

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

To observe changes to the onesignalId or externalId you can add a custom method to the event:

OneSignal.User.Changed += _userStateChanged;

private void yourOnUserStateChangedMethod(object sender, UserStateChangedEventArgs e) {
...
}


## Subscriptions

Expand Down Expand Up @@ -165,7 +173,10 @@ The user name space is accessible via `OneSignal.User` and provides access to us
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `IPushSubscription PushSubscription` | *The push subscription associated to the current user.* |
| `string Language` | *Set the 2-character language either as a detected language or explicitly set for this user.* |
| `Changed` <br><br> `event EventHandler<UserStateChangedEventArgs> Changed` <br><br> `UserStateChangedEventArgs { UserChangedState State }` | *Adds a change event that will run whenever the onesignalId or externalId has been changed.* |
* |
| `PushSubsription.Changed` <br><br> `event EventHandler<PushSubscriptionChangedEventArgs> Changed` <br><br> `PushSubscriptionChangedEventArgs { PushSubscriptionChangedState State }` | *Adds a change event that will run whenever the push subscription has been changed.* |
* |
| `void AddAlias(string label, string id)` | *Set an alias for the current user. If this alias already exists it will be overwritten.* |
| `void AddAliases(Dictionary<string, string> aliases)` | S*et aliases for the current user. If any alias already exists it will be overwritten.* |
| `void RemoveAlias(string label)` | *Remove an alias from the current user.* |
Expand Down
7 changes: 7 additions & 0 deletions OneSignalExample/Assets/OneSignal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- iOS crash when calling OneSignal.User.PushSubscription.Id and OneSignal.User.PushSubscription.Token when they are null.

## [5.1.0]
### Fixed
- Add getters for the user state that includes onesignalId and externalId
- Add observer for the user state
### Changed
- Updated included Android SDK to [5.1.4](https://github.com/OneSignal/OneSignal-Android-SDK/releases/tag/5.1.4)

## [5.0.6]
### Fixed
- Duplicate symbol errors when building with other iOS plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
using OneSignalSDK;
using OneSignalSDK.Notifications;
using OneSignalSDK.InAppMessages;
using OneSignalSDK.User;
using OneSignalSDK.User.Internal;
using OneSignalSDK.User.Models;
using OneSignalSDK.Debug.Models;
using OneSignalSDK.Debug.Utilities;
Expand Down Expand Up @@ -159,6 +161,7 @@ private void Start() {

// Setup the below to listen for and respond to state changes
OneSignal.User.PushSubscription.Changed += _pushSubscriptionChanged;
OneSignal.User.Changed += _userStateChanged;
}

/*
Expand Down Expand Up @@ -211,6 +214,11 @@ private void _pushSubscriptionChanged(object sender, PushSubscriptionChangedEven
_log($"Push subscription changed to current: {JsonUtility.ToJson(e.State.Current)}");
}

private void _userStateChanged(object sender, UserStateChangedEventArgs e) {
_log($"onesignalId changed : {e.State.Current.onesignalId}");
_log($"externalId changed : {e.State.Current.externalId}");
}

/*
* SDK setup
*/
Expand Down Expand Up @@ -298,6 +306,16 @@ public void RemoveAlias() {
OneSignal.User.RemoveAlias(aliasKey);
}

public void GetOneSignalId() {
string onesignalId = OneSignal.User.onesignalId;
_log($"Get OneSignalId <b>{onesignalId}</b>");
}

public void GetExternalId() {
string externalId = OneSignal.User.externalId;
_log($"Get ExternalId <b>{externalId}</b>");
}

/*
* Push
*/
Expand Down
Loading

0 comments on commit d57c900

Please sign in to comment.