Push Notifications for the Web

Hi all!

I’ve just read Chrome has implemented support for push notifications in the web: http://updates.html5rocks.com/2015/03/push-notificatons-on-the-open-web

I’m wondering how everyone’s handling push notifications in their Cocos2d-js apps (I’m guessing there’s a JSB module for that?), and, perhaps: once Firefox/Spidermonkey adds support for this too, maybe we’ll be able to handle push notifications for compiled cocos2d-js apps in all javascript code?

As for now, we don’t have push notification support in Cocos, but it will be a great feature. So I added an issue:

https://github.com/cocos2d/cocos2d-x/issues/11541

Got it, thanks!

So, since we are at it, let’s say I want to make a game which should keep running in the background after the app has been closed in a mobile device, and after x time I want it to pop a notification to the user telling him something and with an icon: there’s currently no way of doing that, right?

@ZippoLag

I have an idea to do so but there is a problem, the function can’t be executed when in background

First, you can have a look on this Push Notification for iOS and Android.
https://www.parse.com/docs/push_guide#sending-channels/iOS

You have to separately integrate Parse into iOS and Android project in frameworks/runtime-src/ with respected platform SDK.

Then you still need to integrate Parse JS SDK in Cocos2d-JS project src.

After that you can try schedule a function to check and auto send the Push Notification from app in javascript to the user.
https://www.parse.com/docs/push_guide#options-data/JavaScript

Here is the problem, do you have any method to let the app run in background and call the send push notification function?

init : function ()
{
	var self = this;
	
	cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function()
	{
                    cc.log("EVENT_HIDE);
		self.schedule(self.sendPushNotification, 5);
	});
},

sendPushNotification : function()
{
	Parse.Push.send(
	{
		channels: ["Channel"],
		data: 
		{
			alert: "Great",
			badge: "Increment",
			title: "Success!"
		}
	}, 
	{
		success: function()
		{
			cc.log("Push was successful");
		},
		error: function(error) 
		{
			cc.log("Handle error");
		}
	});
}

The sendPushNotification function only fire when in app/reenter app.

Nope, that’s one of the set backs I don’t know how to fix: making the app keep on running in the background, even if the user has “swiped it away” from the running/recent apps in Android.