Skip to content

Commit

Permalink
Merge pull request #690 from OneSignal/AddOneSignalIdAndExternalId
Browse files Browse the repository at this point in the history
Add getters and watchers for oneSignalId and externalId
  • Loading branch information
jinliu9508 committed Feb 27, 2024
2 parents f02062b + 085703d commit 3ad2961
Show file tree
Hide file tree
Showing 20 changed files with 973 additions and 5 deletions.
13 changes: 13 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 _userStateChanged(object sender, UserStateChangedEventArgs e) {
...
}


## Subscriptions

Expand Down Expand Up @@ -165,7 +173,12 @@ 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.* |
| `string OneSignalId` | *The UUID generated by OneSignal to represent a user, empty if this is currently unavailable.* |
| `string ExternalId` | *The External ID is OneSignal's default and recommended alias label. This should be the mainidentifier you use to identify users. It is set when calling the [OneSignal.login] method.* |
| `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
4 changes: 4 additions & 0 deletions OneSignalExample/Assets/OneSignal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- iOS crash when calling OneSignal.User.PushSubscription.Id and OneSignal.User.PushSubscription.Token when they are null.
### Changed
- Add public getters for OneSignalId and ExternalId in the User namespace
- Add public event handler OneSignal.User.Changed that fires when the OneSignalId or ExternalId changes
- Updated included Android SDK to [5.1.4](https://github.com/OneSignal/OneSignal-Android-SDK/releases/tag/5.1.4)

## [5.0.6]
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using OneSignalSDK;
using OneSignalSDK.Notifications;
using OneSignalSDK.InAppMessages;
using OneSignalSDK.User;
using OneSignalSDK.User.Models;
using OneSignalSDK.Debug.Models;
using OneSignalSDK.Debug.Utilities;
Expand Down Expand Up @@ -159,6 +160,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 +213,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 +305,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 3ad2961

Please sign in to comment.