Sign In Register

How can we help you today?

Start a new topic
Answered

push notifications, unity, and the Cross Platform Native Plugins - Ultra Pack asset

So I'm hitting my head against the wall trying to get push notifications working in Unity. For the handling of push notifications on the client side, I'm using the Cross Platform Native Plugins - Ultra Pack. On the server side, I’m using GameSparks.


Things I've Done

     In Unity
          Replicated the Methods and Callbacks from the Cross Platform Native Plugin demo script in my game manager script
          On events such as DidReceiveLocalNotificationEvent and DidReceiveRemoteNotificationEvent, the received notification is scheduled
          You can see these in this excerpt script http://pastebin.com/KQx9qnpW
          In Cross Platform Native Plugin
                    The Android Sender ID is added and set as my google project’s project number

          In GameSparks
                    Saved the Development Push Certificate to Game Sparks’ Apple Configuration window with Push Enabled

                    Saved Google App ID (my google project’s project id) and GCM API key to Game Sparks’ Google Configuration window

          Things That Work
                    Local notifications

                    On Android

                              Registering and Enabling of Notifications via Cross Platform Native Plugin as well as push id registration via game sparks

                              Test Push Notification Google via Game Sparks with a Response of Status code: 200

                                        However, this only happens when the app is open. The notification appears when the app i put in the background

                    On iOS

                              Registering and Enabling of Notifications via Cross Platform Native Plugin as well as push id registration via game sparks

          Things That Don't Work
                    On Android

                              Noted on what did work for Android, remote notifications didn't work while the app was in the background.

                    On iOS

                              Test Push Notification Apple Development with an Exception: Failed to deliver notification with error code 8, Delivery error code: INVALID_TOKEN Message ID: 1, Send retry count: 0


So is there anything I'm doing wrong here? I'm so lost. How do I get push notifications to appear with the app in the background and why is the iOS token invalid?

Note: I did try to integrate a fix I found in this post

Some System Info
Unity 5.3.4.1
iOS 9.3.2
Android 4.2.2 & 4.4.4
GameSparks 5.3.5.171
Native Plugins 1.3.1.1


Best Answer

Fixed it! The gamesparks notification payload wasn't what the Cross Platform Native Plugins asset was expecting. Gotta implement that custom JSON for android. Lol, this thread looks weird now but thank you for making an awesome service!


hmmm I'm actually having trouble with messages on Android.


So using this code on the Test Push Notification Google window in Integrations works fine

 

{  
   "ticker_text":"${summary}",
   "content_text":"${subtitle}",
   "content_title":"${title}",
   "custom-sound":"notification.mp3",
   "large-icon":"NativePlugins.png",
   "messageCount":"1"
}

But when using it in the Messages section > [whatever message] > Message Delivery Options > Advanced configuration Android JSON, it doesn't work.


Works on iOS by default though.

Hi One More Turn


What code are you using to send this?


An example of how to send in cloud code


var msgCode = "push";

var msg = Spark.message(msgCode);;

msg.setMessageData({"summary":"myMessage", "title":"title", "subtitle":"subtitle"});

msg.setPlayerIds(myPlayer.getPlayerId());

msg.setSendAsPush(true);

msg.send();


Regards

Katie

This is from the standard messages ie AchievementEarnedMessage, ChallengeAcceptedMessage, ChallengeChangedMessage, etc.


Example, for ChallengeTurnTakenMessage, my iOS device gets every push. My Android device, however, does not.


Even when populating ChallengeTurnTakenMessage's Advanced configuration's Android JSON with the payload that does work (my previous post has it) in the Test Push Notification Google window on my device, my android device doesn't generate a push notification.

any idea?

should I started a new thread for my android question?

ok so I got push notifications to work on iOS! Turns out I needed to test the production certificate since I was on an Ad Hoc build (built through Unity Cloud Build).

But my problem still remains with android.

When I test a remote notification on android, my game prints that its received when the game opens. But not notification is created when the app is in the background.

No errors display when testing the remote notification from gamesparks.

Answer

Fixed it! The gamesparks notification payload wasn't what the Cross Platform Native Plugins asset was expecting. Gotta implement that custom JSON for android. Lol, this thread looks weird now but thank you for making an awesome service!

Login to post a comment