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.
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:
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.
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!
I'm having trouble sending a badge value to the message template using:
"badge": "${data.badge}"
Could someone please explain how to do this? I can send the title and body data but the badge (integer) value is not sent or showing on the app icon.
How do i Test the template in the Test Harness????
Andrea Marchetti
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.