Getting OneSignal UserID with Unity (C#)

2019-08-22 01:19发布

In my app, I have some push notification subscribers (OneSignal). I am trying to get the user id's like this:

OneSignal.GetIdsAvailable(IdsAvailable);
....
....
private void IdsAvailable(string userID, string pushToken)
{
    playeridx = userID;
    System.Diagnostics.Debug.WriteLine("UserID:" + userID);
    System.Diagnostics.Debug.WriteLine("pushToken:" + pushToken);
}

But I get an error: "OneSignal does not contain a definition for GetIdsAvailable."

Any ideas?

2条回答
放荡不羁爱自由
2楼-- · 2019-08-22 01:37

As I am seeing, we must use the code bellow to get the UserID. But, which event is triggered when the UserID arrives from Onesignal? if I use the UserID right after this line, it always has the UserID? It sounds strange for me, because, sometimes it could not had received the UserID yet.

OSPermissionSubscriptionState state = OneSignal.GetPermissionSubscriptionState();
extraMessage += " UserId: "+state.subscriptionStatus.userId;
查看更多
放荡不羁爱自由
3楼-- · 2019-08-22 01:44

It looks like you are using a method found in the OneSignal Windows SDK. If you want to do this in Unity, setup the Unity SDK (if you haven't done so already) and then perhaps use GetPermissionSubscriptionState to retrieve the userId and pushToken of the current user, instead of using .GetIdsAvailable().

查看更多
登录 后发表回答