I’ve noted that the notifications have a title and a description, but Solar2D just include the alert (the description) setup. Solar2D assume that the name of the app as the title of the notification. Please, see the example below, the second notification is from my game and you will see that the title match the name of the app.
I was able to successfully use both the title and alert on my push notfications for both android and ios using Firebase and their push API.
The test code below should send the push via Firebase to one specific device.
local json = require("json")
local FCMkey = "key=YOUR_FIREBASE_KEY"
local deviceToken = "YOUR_DEVICE_TOKEN"
local title = "👀 👀 Keep your eyes peeled 👀 👀"
local alert = "There may be obstacles 💥 in the way!"
local pushUrl = "https://fcm.googleapis.com/fcm/send"
local headers = {}
local body = {}
headers =
{
["Content-Type"] = "application/json",
["Authorization"] = FCMkey
}
body =
{
["to"] = deviceToken,
["notification"] =
{
["title"] = title,
["body"] = alert
},
}
-- end
local function pushResponse(event)
print("pushResponse")
end
local params = {}
params.headers = headers
params.body = json.prettify(body)
network.request( pushUrl, "POST", pushResponse, params )
Then in your notification listener on that device, setup the native.showAlert for each OS. The title is buried in the payload which is different between android and ios.
local function notificationListener( event )
if event.type == "remoteRegistration" then
-- do registration stuff
elseif event.type == "remote" then
if system.getInfo( "platform" ) == "android" then
native.showAlert( event.androidPayload.title, event.androidPayload.body, {"Ok"} ) -- Android
else
native.showAlert( event.alert.title, event.alert.body, {"Ok"} ) -- IOS
end
end
end
Runtime:addEventListener( "notification", notificationListener )
notifications.registerForPushNotifications( { useFCM=true })
Hope this works for you.
Scott