Corona SDK

How to integrate Pushwoosh SDK into your Corona project

Supports iOS, Android

Note:

iOS Simulator can neither subscribe to nor receive push notifications.
Android Emulator works fine though.

Download Sample

To integrate Pushwoosh into your Corona application follow these steps:

1. Configure your Corona project

First, make sure a specific table is included within your config.lua file. You can simply copy/paste from the example, but ensure that the ‘notification’ table is within the ‘application’ table, not the ‘content’ table.

config.lua:

application =
{
    content =
    {
        width = 320,
        height = 480
    },
 
    notification =
    {
        google = { projectNumber = "YOUR_GOOGLE_PROJECT_NUMBER_HERE" },
        iphone =
        {
            types =
            {
                "badge", "sound", "alert"
            }
        }
    }
}

The presence of a ‘notification’ table in your config.lua file will trigger the “Do you wish to allow ‘Your App’ to receive Push Notifications?” popup on iOS when the user first launches your app.

Replace "YOUR_GOOGLE_PROJECT_NUMBER_HERE" with your real Google Project Number.

2. Add notification plugin and permissions for Android to your build.settings file

build.settings


settings = 
{
	plugins =
	{
		["plugin.notifications"] =
		{
			publisherId = "com.coronalabs"
		},
	},
	orientation =
	{
		default = "portrait",
		supported = { "portrait" }
	},
  android =
	{
		permissions =
		{
			{ name = ".permission.C2D_MESSAGE", protectionLevel = "signature" },
		},
		usesPermissions =
		{
			"android.permission.INTERNET",
			"android.permission.GET_ACCOUNTS",
			"android.permission.RECEIVE_BOOT_COMPLETED",
			"com.google.android.c2dm.permission.RECEIVE",
			".permission.C2D_MESSAGE",
		},
	},
}

3. Download Pushwoosh module from https://github.com/Pushwoosh/pushwoosh-corona-sdk/blob/master/pushwoosh.lua

4. Add push notification handling code to your main.lua file:

main.lua:

local pushwoosh = require( "pushwoosh" )

local function onNotification( event )
	native.showAlert( "remote notification", json.encode( event.data ), { "OK" } )
end

local function onRegistrationSuccess( event )
	print( "Registered on Pushwoosh" )
end

local function onRegistrationFail( event )
	native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred. Please try again later from the application settings.", { "OK" } )                  
end

Runtime:addEventListener( "pushwoosh-notification", onNotification )
Runtime:addEventListener( "pushwoosh-registration-success", onRegistrationSuccess )
Runtime:addEventListener( "pushwoosh-registration-fail", onRegistrationFail )

local launchArgs = ...

pushwoosh.registerForPushNotifications( "PUSHWOOSH_APPLICATION_ID", launchArgs ) -- specify your application Id

Replace "PUSHWOOSH_APPLICATION_ID" with your real Pushwoosh Application ID.

Easy, isn’t it?

Corona SDK

How to integrate Pushwoosh SDK into your Corona project