Skip to content

Commit

Permalink
Keep the internal changed handler in memory
Browse files Browse the repository at this point in the history
remove test calls to User.OneSignalId and User.ExternalId
  • Loading branch information
emawby committed Mar 21, 2024
1 parent 62b79a8 commit 9f6c4f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion OneSignalSDK.DotNet.Android/AndroidUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ public string Language

public IPushSubscription PushSubscription { get; } = new AndroidPushSubscription();

private InternalUserChangedHandler? _userChangedHandler;

public void Initialize()
{
OneSignalNative.User.AddObserver(new InternalUserChangedHandler(this));
_userChangedHandler = new InternalUserChangedHandler(this);
OneSignalNative.User.AddObserver(_userChangedHandler);
((AndroidPushSubscription)PushSubscription).Initialize();
}

Expand Down
9 changes: 6 additions & 3 deletions OneSignalSDK.DotNet.iOS/iOSUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public string Language

public IPushSubscription PushSubscription { get; } = new iOSPushSubscription();

private InternalUserChangedHandler _userChangedHandler;

public void Initialize()
{
OneSignalNative.User.AddObserver(new InternalUserChangedHandler(this));
_userChangedHandler = new InternalUserChangedHandler(this);
OneSignalNative.User.AddObserver(_userChangedHandler);
((iOSPushSubscription)PushSubscription).Initialize();
}

Expand All @@ -33,7 +36,7 @@ public string ExternalId
{
get => OneSignalNative.User.ExternalId;
}
public event EventHandler<UserStateChangedEventArgs> Changed;
public event EventHandler<UserStateChangedEventArgs>? Changed;

public void AddAlias(string label, string id) => OneSignalNative.User.AddAliasWithLabel(label, id);
public void AddAliases(IDictionary<string, string> aliases) => OneSignalNative.User.AddAliases(NativeConversion.DictToNSDict(aliases));
Expand Down Expand Up @@ -73,7 +76,7 @@ public InternalUserChangedHandler(iOSUserManager manager)
_manager = manager;
}

public void OnUserStateDidChangeWithState(OSUserChangedState state)
public override void OnUserStateDidChangeWithState(OSUserChangedState state)
{
var current = new InternalUserState(state.Current.OnesignalId, state.Current.ExternalId);
var userChangedState = new UserChangedState(current);
Expand Down
3 changes: 0 additions & 3 deletions Samples/OneSignalApp/Models/MainPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ public MainPageModel(Page page)
OneSignal.InAppMessages.DidDismiss += InAppMessages_DidDismiss;
OneSignal.InAppMessages.Clicked += InAppMessages_Clicked;

string onesignalId = OneSignal.User.OneSignalId;
string externalId = OneSignal.User.ExternalId;

IsPushEnabled = OneSignal.User.PushSubscription.OptedIn;
HasPushPermission = OneSignal.Notifications.Permission;
IsIAMPaused = OneSignal.InAppMessages.Paused;
Expand Down

0 comments on commit 9f6c4f5

Please sign in to comment.