Getting OneSignal UserID with Unity (C#)

感情迁移 提交于 2019-12-12 06:28:07

问题


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?


回答1:


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().




回答2:


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;


来源:https://stackoverflow.com/questions/44957612/getting-onesignal-userid-with-unity-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!