Skip to content

Commit

Permalink
Make IDs nullable when unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed Feb 21, 2024
1 parent a59eb24 commit 3d0f695
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions MIGRATION_GUIDE_v3_to_v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ 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.* |
| `string OneSignalId` | *The UUID generated by OneSignal to represent a user, null 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. Return null if this is currently unavailable.
* |
| `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.* |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ public void RemoveAlias() {
}

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

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

Expand Down
10 changes: 8 additions & 2 deletions com.onesignal.unity.android/Runtime/AndroidUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ public AndroidUserManager(AndroidJavaClass sdkClass) {
}

public string OneSignalId {
get => _user.Call<string>("getOnesignalId");
get {
string id = _user.Call<string>("getOnesignalId");
return string.IsNullOrEmpty(id)? null : id;
}
}

public string ExternalId {
get => _user.Call<string>("getExternalId");
get {
string id = _user.Call<string>("getExternalId");
return string.IsNullOrEmpty(id)? null : id;
}
}

public IPushSubscription PushSubscription {
Expand Down
4 changes: 2 additions & 2 deletions com.onesignal.unity.core/Runtime/User/IUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public UserStateChangedEventArgs(UserChangedState state) {
/// </summary>
public interface IUserManager {
/// <summary>
/// The UUID generated by OneSignal to represent a user, empty if this is currently unavailable.
/// The UUID generated by OneSignal to represent a user, null if this is currently unavailable.
/// </summary>
string OneSignalId { get; }

/// <summary>
/// The External ID is OneSignal's default and recommended alias label. This should be the main
/// identifier you use to identify users. It is set when calling the [OneSignal.login] method.
///
/// This is empty if the External ID has not been set.
/// This is null if the External ID has not been set.
/// </summary>
string ExternalId { get; }

Expand Down

0 comments on commit 3d0f695

Please sign in to comment.