Sign In Register

How can we help you today?

Start a new topic
Answered

Push notifications on Unity

Hello,


I'm trying to implemeng push notifications on Android and also iOS on my Unity's project.


For Android, I obtained the GCM API key from Firebase/Google consola.


I think that I have set properly the part of Gamesparks (I hope)


But how I can send the PushId from Unity's client?


On this tutorial https://docs.gamesparks.com/tutorials/social-features/configuring-android-push-notifications.html seems to easy that don't explain this part...

private void sendRegistrationIdToBackend() {
   // Your implementation here.
 }

It would greatly appreciate any help!!


Many thanks and sorry for my english grammar ;-)



Best Answer

Hi Agustin


You need to send the pushId to Gamesparks using a PushRegistrationRequest

In Unity  

    using GameSparks.Api;
    using GameSparks.Api.Requests;
    using GameSparks.Api.Responses;

    new PushRegistrationRequest()
        .SetPushId(pushId)
        .Send((response) => {
        string registrationId = response.RegistrationId; 
        GSData scriptData = response.ScriptData; 
        });

 

For Unity you will need a 3rd party plugin for get the push Id, there are many different ones available via the unity store.


Regards

Katie


Answer

Hi Agustin


You need to send the pushId to Gamesparks using a PushRegistrationRequest

In Unity  

    using GameSparks.Api;
    using GameSparks.Api.Requests;
    using GameSparks.Api.Responses;

    new PushRegistrationRequest()
        .SetPushId(pushId)
        .Send((response) => {
        string registrationId = response.RegistrationId; 
        GSData scriptData = response.ScriptData; 
        });

 

For Unity you will need a 3rd party plugin for get the push Id, there are many different ones available via the unity store.


Regards

Katie

What is pushId? your docs are incomplete i guess. how do i get pushId in unity for android if im using FCM. I followed this link as your docs instruct so the token which I get when i set up FCM messaging like this as show in the picture. Please help me.

Untitled.png
(29.8 KB)

Hi Saad Anees


A push id is a token that is received from the device.

In unity a plugin in is required to get a push Id from the device.

In the FCM plugin the push id is in the OnTokenReceived function in token.Token

 

C#
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
  UnityEngine.Debug.Log("Received Registration Token: " + token.Token);
}

From your code it looks like you are sending the right information.

Is OnTokenReceived not firing or are you getting any errors?


Regards

Katie



Thanks for your quick response. Yes its not firing. Also correct me that do i have to make build to see if its firing or does it work in unity editor too? 

Per FCM docs, Firebase will not initialize in the editor. You have to compile it and test it on your device.

Hello Christopher,

Yes you are right. I built it and i am getting pushIds in scriptData. But I still dont get push notification. Do i still need third party plugin to show notification? 

Regards,
Saad

Did you set up the payload JSON in GameSparks?

Do you mean FCM template in google integration page?

Yes

 

yes I did as mentioned GameSparks docs to setup FCM. One thing more. I tried using Firebase Notification to send message via push token. I copied pushId which received in in NoSQL and it gave an error saying Invalid Token. Then i tried different option to send message to bundle identifier of the app and I received message as push successfully. 

Print out the Token via Debug.Log and make sure it matches the one put into NoSQL. If you are Android, you can use adb logcat | find "Unity"

 

It doesn't get called in editor. and i dont know adb logcat. let me see that. thanks anyway.

adb will be in your android sdk. personally, I set up a local variable to always point to the sdk so I can just do 'adb logcat' in cmd

Hello,


I asked one of the support member of GameSparks and he said the token i got is fine. I also tried GCM tutorial and test GCM from GameSparks. I got Status code: 200 which means response is okay. But i didn't receive any notification.

Login to post a comment