Sign In Register

How can we help you today?

Start a new topic

Push notifications are sent correctly but doesn't show up in iOS

I have set correctly my certificates, target's capabilities are correctly set in xCode. The PushRegistrationRequest works fine, I get a new push registration (IOS/APNS) in the player entry in noSQL database.


However nothing shows up on my iPhone when I try to send a push notification through Cloud Code or by testing it in the tester inside the integrations page, here I get "Message Sent:" in green, nothing else. The Cloud Code works on Android though.


Hi Andrea

Have you been following the iOS push notification guide here
Do you have the app closed when testing.

Regards
Katie

 

I did, but since I am using Unity I wrote this instead of using the Obj-C code.

using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;

public class PushNotificationsManager : MonoBehaviour
{
	void Start()
	{
		DontDestroyOnLoad (gameObject);
		
		NotificationServices.RegisterForNotifications(
			NotificationType.Alert |
			NotificationType.Badge |
			NotificationType.Sound, true);

		if (!PlayerPrefs.HasKey ("notFirstTime"))
			StartCoroutine (WaitForTokenAndRegistrate());
	}

	IEnumerator WaitForTokenAndRegistrate ()
	{
		yield return new WaitUntil (() => NotificationServices.deviceToken != null);
		yield return new WaitUntil (() => GS.Available); 

		byte[] token = NotificationServices.deviceToken;
		if (token != null)
		{
			string hexToken = System.BitConverter.ToString (token);

			Debug.Log ("Push Token is received: " + hexToken);
			new PushRegistrationRequest ()
				.SetPushId (hexToken)
                                // i tried with IOS too, doesn't change anything.
				.SetDeviceOS ("APNS")
				.Send ((response) => {
					if (!response.HasErrors)
						Debug.Log ("iOS registered for Push on GS");
			});
		}
	}
}

  

Yes, I do have the app closed when testing.

Hi Andrea


"IOS" is correct for SetDeviceOS

What does your push id look like, it should be a long code with no hyphens.

If it has hyphens these need to be removed.


Regards

Katie

Oh ok, let me try by removing hyphens.
Even if I've already tried to change it manually in the noSQL tab, by removing the hyphens and it didn't worked anyway.


I've just tried and nothing changed. I receive nothing.

Since my project is for Android too I need Firebase to send push notifications and Unity doesn't remove Firebase when building for iOS. So at the start of the app there are some Firebase process going on, before everything else. Is this a possible cause?

NEWS: I am trying to send the notification with an specific app I found on the App Store which allows me to test the APNS: I receive the notification on my iPhone.


So then I've tried again from the GameSparks Portal and I don't receive anything.      :'(


Here's my set up:

image


Since I've just seen that this program is using a different message template I tried to change it into this on the portal too.

{
  "aps": {
    "alert": {
      "title": "${data.title}",
      "body": "${data.body}"
    },
    "sound": "default",
    "badge": 9
  }
}

 Doesn't change.

Ok.... If I write the following code into the Custom JSON in the test it works!

BUT how to customise it then? It seems that the template isn't considered.

{
  "aps": {
    "alert": {
      "title": "hey",
      "body": "yeah"
    },
    "sound": "default"
  }
}

 PS: Sorry for the various post.

My goodness, after days I have make it.


So the solution is:

- while testing in the Integrations tab the custom JSON doesn't consider the template by default, I have to write the whole payload.

- this is the correct template for iOS: 

{
  "aps": {
    "alert": {
      "title": "${data.title}",
      "body": "${data.body}"
    },
    "sound": "default",
    "badge": 9
  }
}

 - to test the template the Test Harness must be used.


Please update the template into the tutorial! 


Thank you for the support.


2 people like this

You guys should really update the documentation to have the template Andrea posted there. I've been going crazy looking for the right combination for the Push Notifications on iOS to work and couldn't find it in the documentation until I got with this post.


Thanks for posting the solution Andrea, really appreciated!

Login to post a comment