Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Why the player Id is empty from oneSignal on Xamarin? Just in iOS

SpiellerMxSpiellerMx Member ✭✭
edited November 2019 in Xamarin.Forms

I'm having a little problem getting the player Id from Xamarin. I'm making an application in Xamarin Forms, it works for Android, but when I try to get it on iOS the string is Empty.

Then, when I want to get the value of "playerId" (My var) it is Empty. This happens just in iOS--when I do this on Android it works fine. Obviously before I register the app with the OneSignal Key, my device(iPhone) is registered on the OneSignal page and I can receive push notifications. I need get the playerId to save it on my DataBase.

This is my code:

string playerId="";

OneSignal.Current.IdsAvailable(new Com.OneSignal.Abstractions.IdsAvailableCallback((playerID, pushToken) =>
                                playerId = playerID;


  • LandLuLandLu Member, Xamarin Team Xamurai

    Where did you call this event?
    It seems client needs some time to register the OneSignal after the push notification permission has been accepted:
    You can try to use OSSubscriptionStateObserver to get the user id. Here is the implementation for swift:

  • SpiellerMxSpiellerMx Member ✭✭
    edited November 2019


    I'm calling the event on my App.xaml.cs and I tried after my login authentication on a ViewModel class too. Just for a test I tried on AppDelegate.cs and I had the same problem.

    I observed that when I run the application on iOS it doesn't even join on the method to assign the PlayerID.

    When I do the test on Android, it works fine.

  • danielparedes97danielparedes97 Member ✭✭✭

    @SpiellerMx I had the same issue that you, and I think that the problem comes because with android it's almost instant, but for iOS it takes roughly 2 seconds from the time my app starts to the time the Id is available, so I simply had to make a delay of 2 seconds and now I can get the UserId.

  • PotatoBoyPotatoBoy Member

    @SpiellerMx Did you fix it? i'm having the exact same problem. So far i've discovered that the delegate "IdsAvailableCallBack" is not getting called when working on iOS. I'm not having any problems on Android.

  • SpiellerMxSpiellerMx Member ✭✭
    edited August 6


    I resolved my issue with this code on the App.cs:


    The 'getID' method just have this: (The UserSettings.PlayerId is the variable that I want to get the PlayerId)

     private void getID(string playerID, string pushToken)
                UserSettings.PlayerId = playerID;
Sign In or Register to comment.