Part 1 - OneSignal Plugin Example

Part 1 - OneSignal Solar2D Push Notification Plugin Example

OneSignal is a free push notification service for mobile apps. They've partnered with Solar2D to make it easy to use OneSignal in your app. 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

OneSignal.DisableAutoRegister()
OneSignal.Init("b2f7f966-d8cc-11e4-bed1-df8f05be55ba", "703322744261", DidReceiveRemoteNotification)
OneSignal.EnableInAppAlertNotification(true)

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