Hi there,

We are using the Unity and the PushWoosh services and plugin for iOS. I am registering to the remote notifications using the PushNotificationsIOS.cs class by PushWoosh (done in the Start method) as shown below:

    // Use this for initialization
void Start () 
{
    Debug.Log ( "PushWoosh: Start - registering remote notifications" );
    registerForRemoteNotifications();
    setListenerName(this.gameObject.name);

    Debug.Log ( "PushWoosh: PushNotificationsIOs:Start - the push token is:" );
    Debug.Log(getPushToken());
    Debug.Log ( "PushWoosh: PushNotificationsIOs:Start - exiting" );
}

When running on the device this print returns an empty string!!!

I also retrieve the device token using a piece of code shown below - this time comparing to the Unity native code to get the token:

    public void Update()
{
    if (Counter++ < 5) 
    {
        // The device token will not exist for the first several iterations.

        Token = NotificationServices.deviceToken;
        if (Token != null) 
        {
            string tokenString = System.BitConverter.ToString (Token).Replace ("-", "").ToLower ();
            Debug.Log ("============ Remote notifications  - OnTokenRecieved ");    
            Debug.Log (tokenString);

            // And now test the PushWoosh token as well
            string      tokenPushWoosh = PushNotificationsIOS.getPushToken();
            Debug.Log ( "PushWoosh: PushNotificationsIOs:Start - the push token is: " + tokenPushWoosh" );

        }
    }
}

Again, while the native code did return the right token, the PushWoosh returned an empty string!

I want to make sure that I test this correctly or that this is nothing to get worried about - I wouldn't want to release a version and find out that PushWoosh plugin does not generate the token correctly and as a result no user will get notifications.

Thanks for the help

asked 14 Jan '15, 15:48
adiblev's gravatar image

adiblev
1112

I cannot reproduce the second issue, but let me explain the first one.
Push token registration is asynchronous procedure. Therefore if you query the push token straightaway after the registration function call - you will receive empty string as there is no push token obtained yet.
Look at the callback function: void onRegisteredForPushNotifications(string token)
It will be called when push token has been received. After that getPushToken() method will start returning value. On subsequent launches when push token is obtained already, the function will return the value straightaway.

If you always receive empty token - please share the logs from the device console.

permanent link
answered 15 Jan '15, 05:43
shader's gravatar image

shader
3.9k7

Thanks shader,

You are right, I put a count delay print at the Update method to give time for the registration to complete as Unity doesn't give have callback event - At this point in time PushWoosh token is still empty?!

Following you good advise I removed the print from the PushWoosh 'Start' and put it within the method 'onRegisteredForPushNotifications' - this was never called and no string was returned as the token.

Weirdly - I am getting notify from PushWoosh on Sandbox/Production test devices (different tokens), but I never got the token from the PushWoosh code, only from Unity method

(15 Jan '15, 16:39) adiblev adiblev's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×88
×49
×38

question asked: 14 Jan '15, 15:48

question was seen: 3,037 times

last updated: 15 Jan '15, 16:39