Part 1 - OneSignal Plugin Example

Part 1 - OneSignal Corona SDK Push Notification Plugin Example

OneSignal is a free push notification service for mobile apps. They’ve partnered with Corona SDK to make it easy to use OneSignal in your Corona Apps. Simply follow our directions to get started.


setup

build.settings

settings = {
	orientation = {
		default = "portrait",
		supported = { "portrait", "portraitUpsideDown" }
	},
	
	iphone = {
		plist = {
			UIBackgroundModes = {"remote-notification"},
			UIStatusBarHidden = false,
			UIPrerenderedIcon = true, -- set to false for "shine" overlay
		}
	},
	
	plugins = {
    ["plugin.OneSignal"] =
    {
        publisherId = "com.onesignal"
    },
		["plugin.google.play.services"] =
		{
			publisherId = "com.coronalabs",
			supportedPlatforms = { android=true, ["android-kindle"]=true }
		},
  },
}

main.lua

local OneSignal = require("plugin.OneSignal")

receive notificaton

function DidReceiveRemoteNotification(message, additionalData, isActive)
    native.showAlert("message:", message, { "OK" } )
end

init

replace the following id&number with yours


Butoon - Get Ids

pressing the button to enable user to receive Notification

OneSignal.RegisterForNotifications()


check

OneSignal.IdsAvailableCallback( function (userId, pushToken)
    print("userId:" .. userId)
    if (pushToken) then
        print("pushToken:" .. pushToken)
    end
end)

if pushuToken is nil , there was a connection issue or on iOS notification permissions were not accepted.


Test

send a push notification from OneSignal while your app is under each state of