Sign In Register

How can we help you today?

Start a new topic

FCM Firebase Push Notifications not Received using GameSparks Messages. (Android)

Pushing notifications with the Firebase console works.  


However, I do not receive any notifications on the Android device when using messages from GameSparks.


Google Integration FCM Template   

{
  "notification": {
    "title": "${data.title}",
    "body": "${data.body}"
  }
}

   


MyScriptMessageExtension FCM Template 

{
  "notification": {
    "title": "${data.title}",
    "body": "${data.body}"
  }
}

 

in addition to these templates, I've also tried ${title} and ${summary}, to no avail.


Cloud Code that accepts pId as playerId to send message to.

var msg = Spark.message("MyScriptMessageExtension");
msg.setPlayerIds([Spark.getData().pId]);
msg.setSendAsPush(true);
msg.setSendViaSocket(false);
msg.setMessageData({"title":"A Title","body":"Some Message."});
msg.send();

   


PushRegistrationRequest Code: 

public class PushNotificationManager : MonoBehaviour {

	Firebase.DependencyStatus dependencyStatus;
	// Use this for initialization
	void Start () {
		Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
      		dependencyStatus = task.Result;   
			InitializeFirebase();   		
		});
	}
	protected  void InitializeFirebase() {
		if (dependencyStatus != Firebase.DependencyStatus.Available) {			
			Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
			return;
		}
  		Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
		Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
		// Firebase.Messaging.FirebaseMessaging.SubscribeAsync(topic).ContinueWith(task => {
		// 	Debug.Log("Subscribed Task Fired");
		// });
  	}
	public void OnDestroy() {
		Firebase.Messaging.FirebaseMessaging.MessageReceived -= OnMessageReceived;
		Firebase.Messaging.FirebaseMessaging.TokenReceived -= OnTokenReceived;
	}
	void OnTokenReceived(object sender, TokenReceivedEventArgs token){
		if(token != null){
			string deviceOS = "FCM";
			string pushId = token.Token;
			new PushRegistrationRequest().SetDeviceOS(deviceOS).SetPushId(pushId).Send((r) => {
				if(r.HasErrors){					
					Debug.Log("Errors: " + r.Errors.ToString());
					return;
				}
				if(r != null){
					string registrationId = r.RegistrationId; 
					GSData scriptData = r.ScriptData; 
				}
				
			});
		} else {
			Debug.Log("Token Null");
		}
	}

	void OnMessageReceived(object sender, MessageReceivedEventArgs message){
		Debug.Log("Firebase Message Received From: " + message.Message.From);
	}	
}

 Checked the player record I'm using, and see I get a token:

player.deviceRegIds: d8lkl...w2A: "FCM"


When sending the message using Test Harness, I have tried:

 1. Having the app running in the background.

 2. Swiping the app off the Recent Apps screen.  

 3. Restarting the phone and not running the app.

 4. Turning off/on wifi

 5. Turning off battery saver. 


Apparently force closing can cause the app to not receive notifications, so I have tried all of the above to rule that out.

 




1 person has this question

Is there a way to see logs of the request being sent to firebase from Gamesparks?


I went to API stream and all I could find was this:


 

{
  "@class":".ScriptMessage",
  "data":{
    "body":"Login now to collect your resources.",
    "title":"A New Message"
  },
  "extCode":"MyScriptMessageExtension",
  "messageId":"5b7ef67907420b0521ac09dd",
  "notification":true,
  "playerId":"5b7df17280299a889b4da020",
  "summary":"Login now to collect your resources.",
  "title":"A New Message"
}

 

If I set to send via socket to true, I am able to receive messages in game with the app running as expected.  But with the app closed, I dont get push notifications unless I send from the Firebase console.

This post mentions a 'capture-push-record'?  Where can I find that?


https://support.gamesparks.net/support/discussions/topics/1000085225


I finally decided to try using the Legacy Server Key from Firebase..... and it worked.  


Notification is now being sent from gamesparks.  


1 person likes this
Login to post a comment