Sign In Register

How can we help you today?

Start a new topic
Answered

Problem with Push Notifications - device token coming back empty/null.

I just did this tutorial here:


https://docs.gamesparks.net/howtos/push-notifications/how-to-configure-ios-push-notifications-with-unity


And I'm not having any luck.  When it gets to the code that is in Unity to initialize it, and the fpollowing line is hit:


token = NotificationServices.deviceToken;


That device token is empty.  I added in the variable declarations to get that code to actually compile (looks to be an error in the tutorial), and I've stepped through all of the code, and it's going through and hitting the CBG_RegisterForRemoteNotifications function in the iOS plugins code, because I put an NSLog statement in there, and it gets hit.  And it should hit that case since I'm on iOS 8.


I followed the steps in the tutorial to generate all the certs and stuff, and I have all of that configured.  But maybe I did something wrong?  If so it isn't obvious to me what the problem is.


Also, when my app is on my phone, it DOES ask me for permissions to let the app use push notifications, so the app at least knows about push notifications.  I think it is just registering wrong with the server.


As for the AppID that you create, I did not create another appID, I just used the one I was already using for my game.



Best Answer

Hi Andrew,

Yes I believe you would need to apply your own Audio Clip in Unity.
As for the badge, you could use:

applicationIconBadgeNumber = -1

 to clear the number.

Thanks


Oisin


Answer

Hi Andrew,

Yes I believe you would need to apply your own Audio Clip in Unity.
As for the badge, you could use:

applicationIconBadgeNumber = -1

 to clear the number.

Thanks


Oisin

Okay so I figured out the problem - was user error on my part.


I was trying to get the device token before the notification service was finishing registration.  I put it inside of the Update function and just keep checking until the deviceToken is not null, and it came back.


So now everything is working and notifications are working fine.


I do have 1 question though, and this might be more of a general Unity question, but how do I make it so no badges show up?  I want notifications to show up to let the user know something has happened, but I don't want the badge number to show up over the icon.  I don't like those when I see them, so I don't want to put them on my game.


I did remove the RemoteNotificationType.Badge from being passed in when registering, however the badges are still showing up.


Any ideas about that?

Oh, and also wondering how to get sound to work with the push notifications.  I do have the RemoteNotificationType.Sound being passed in, however I am not getting any sound when I see notifications.  Do I have to provide a custom sound or something?

Anyone have any ideas?


I created a new AppID and provisioning profile today and started from scratch, and I'm still getting the same issue.


I also noticed, that even if I delete all provisioning profiles associated with this game, as well as the AppID, the game was still building and deploying to my phone, even though it had no profiles or AppID.


I'm kind of lost right now as to what is going on and why this isn't working.


Not sure if this matters either, but when I view the provisioning profile in Xcode, in the "Entitlements" section it doesn't have anything for Push Notifications there either.


Just now, when I created the new AppID, the first time I installed it to my phone, again I got the "Game would like to use push notifications, do you want to allow it?" dialog to display, so it looks as though the game is seeing that it wants to use push notifications.  However, the device token is still empty and it fails before I can ever call the GameSparks PushRegistrationRequest because it's getting a null exception trying to generate the pushDeviceToken since the deviceToken is empty.

Login to post a comment