Forum Games Notifications

Discussion relating to game development with Unity

Notifications

Postby Stuart Cook » June 7th, 2014, 8:04 pm

Hi
I'm trying to wrap my head around using Push Notifications using the Client Notifications setup. (using Unity 4.3.4)

This is the code I've got but it never does a successful callback - the 'uniqueID' is a Facebook ID (I've checked this is OK), the EndPointType is the string you see - but the Docs state in 1 place it should be the device token returned from Apple (https://developer.apple.com/library/ios ... eviceToken:), but how do you get that from Unity as that seems to be an Xcode objective C setup?

Basically, have I got the EndPointType bit wrong as the docs aren't exactly clear?

const string EndPointType = "ios-push-notifications";
public static bool IOPushesRegistered = false;
public static Dictionary<string,string> IOPushConfigDict = null;

myPlayerIOClient.Notifications.RegisterEndpoint(
EndPointType, uniqueID, IOPushConfigDict, true,
delegate() {
//success - set check here to say 'I'm registered for pushes!'
IOPushesRegistered = true;
if(Debug.isDebugBuild) Debug.Log("Registered for Yahoo Push Notifications");
}
);

NB My iOS Push Certificates are set up correctly on Apple and the Backend, guaranteed as I used them with PushWoosh before trying to swap to this system.
Stuart Cook
 
Posts: 7
Joined: September 3rd, 2013, 10:06 pm

Re: Notifications

Postby Stuart Cook » June 12th, 2014, 6:36 pm

Ok, I got it working. For anyone else the code should be something like this (for Unity iOS);

myPlayerIOClient.Notifications.RegisterEndpoint(
"ios-push-notifications", tokenUniqueID, IOPushConfigDict, enabled,
delegate() {
//success - set check here to say 'I'm registered for pushes!'
if(Debug.isDebugBuild) Debug.Log("Registered for Yahoo Push Notifications");
},
delegate(PlayerIOError value) {
if(Debug.isDebugBuild) Debug.Log("Failed to register for Yahoo Push Notifications: " + value.ToString());
}
);

where configDict is generally null and the tokenUniqueID is the one from Apple when you register your device for Pushes (I used a Prime31 library call).

ALSO: Make sure permissions are set correctly in your playerIO panel! (ControlPanel->Settings->Connections->Public, the ones for Remote Notifications). I did not realise they had been added as an option, so my bad.
Stuart Cook
 
Posts: 7
Joined: September 3rd, 2013, 10:06 pm

Re: Notifications

Postby Stuart Cook » July 3rd, 2014, 7:29 pm

Since i've got the whole thing working and there seems to be no info elsewhere on the forum, here's a few more useful hints (for iOS, but may translate to android here and there);

In the 'notifications' admin panel for your playerIO/Yahoo game ('my games->Notifications) make sure the loaded certificates are the .P12 files. I know somewhere the documentation states that, but if you read the wording of 'upload your certificates here' I made the mistake of uploading the '.cer' files first time and the system allows them to be uploaded, although they are the wrong files. It's definitely the .P12s!

Definitely use the 'Send Test Notification' option under MyGames->Notifications->RegisteredEndpoints. Not only will you see a correctly registered endpoint, but sending the test will confirm you have set everything up correctly before you write your game 'SendPushNotifications' (or whatever you call it) method.

Finally, here's my send code simplified, just for ease of viewing, it's not hard to do once you get the other stuff working :)
I hope this is useful for those setting up this stuff.

//--------------------------------------------------------------------------------------------
//pass in unique id of recipient you are aiming for (eg FacebookID) and the endpointType, plus the Push Message
//'ept' is either "ios-push-notifications" or "google-cloud-messaging"
//recipientID is whatever your target user used to registered their unique ID on PlayerIO, eg their Facebook ID or e-mail address
//if(send == true) sends the Push immediately, else you can call the Send later

public static void CreateANotificationForIO(string pushTitleMessage, string recipientID, string ept, bool send){
//notifs[] is a Notification array previously set up as 'new Notification[x]' depending on size you need, I'm using 1 only here
notifs[0] = new Notification(recipientID, ept);
notifs[0].Set("alert", pushTitleMessage);
notifs[0].Set("badge", "1"); //adapt as necessary
if(send) SendTheIOPushNotificationNow();
}


//--------------------------------------------------------------------------------------------
//sends the 'notifs' Notification(s) now, make sure the 'notifs' dictionary array is set up
public static void SendTheIOPushNotificationNow(){
myPlayerIOClient.Notifications.Send(
notifs,
delegate() {
//success
if(Debug.isDebugBuild) Debug.Log("Successful Send IO Notification[0]");

},
delegate(PlayerIOError value) {
if(Debug.isDebugBuild) Debug.Log("Failed to Send IO Notifications[0]: " + value.ToString());
}
);
}
Stuart Cook
 
Posts: 7
Joined: September 3rd, 2013, 10:06 pm

Re: Notifications

Postby Henrik » July 29th, 2014, 9:46 pm

Thanks Stuart.

We've added some more checks on the certificate upload page to try to verify if it's the right file you've uploaded. That combined with the test method on the page should help everyone know that they've set it up correctly.
Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: Notifications

Postby Stuart Cook » August 1st, 2014, 1:26 pm

Cheers

As I've posted elsewhere, and you said you are on it, the recipient doesn't get updated Badges or a Sound (at least on iOS, the one I'm doing now). This makes Notifications usable, but unless the Recipent sees the arrival banner and message when it arrives they won't know an update has occurred.

I'll be glad when at least badge updates are working. Let us know ASAP!
Stuart Cook
 
Posts: 7
Joined: September 3rd, 2013, 10:06 pm

Re: Notifications

Postby garethhadfield » September 15th, 2016, 10:59 am

I know the last post is 2 years old, but in case anyone is wondering, the correct call for setting the badges is Notification.Set("badgeCount", "123"); // it's "badgeCount" not "badge"
garethhadfield
 
Posts: 9
Joined: April 12th, 2015, 7:23 am


Return to Games