-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
94 lines (65 loc) · 2.32 KB
/
Copy pathmain.lua
File metadata and controls
94 lines (65 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--
--- For this sample to work you need to:
--- 1. copy and past your *.json google services file from Firebase console into the root of this project.
--- 2. find your appId and replace the blank appId with yours from oneSignal
---
local launchArgs = ...
local json = require "json"
local notify = require( "notification" )
local grid = require( "grid" )
local gridListerner = function(event)
end
local showNotification = function(title, message)
local tableGridOptions = {
--Entire Grid
gridWidth = .80, -- As percentage of full width.
gridHeight = .70, -- As percentage of full height.
backgroundColor = { 0, 0.4, 0.4, 0},
--Title name.
showTitle = true,
titleName = title,
--Header
columnWidthPercent = {1.00},
headerHeight = 150,
headerMultiLine = true,
columnDisplayName = {message},
showColumnHeader = true,
--Columns row
rowDataRoot = "data",
columnDataName = {"None"}
}
grid.DisplayGrid(nil, tableGridOptions, gridListerner)
end
local setNotificationValues = function(notification)
local title
if notification.androidPayload ~= nil then
title = notification.androidPayload.title
else
title = notification.iosPayload.title
end
showNotification(title, notification.alert)
end
if ( launchArgs and launchArgs.notification ) then
print("Resposne: ", json.prettify(launchArgs.notification))
setNotificationValues(launchArgs.notification)
end
local notifyListerner = function(event)
print("Resposne: ", json.prettify(event))
if event.type ~= "remote" then
return
end
setNotificationValues(event.data)
end
local onSystemEvent = function( event )
if ( event.type == "applicationStart" ) then
notify.isDevBuild() -- remove for prod builds.
notify.init(notifyListerner, {
appId = "", -- AppId from One Signal
language = "en", -- Language. I use the candlelight plugin to get this, but you can also use "os.*" library.
sessions = 23 -- I grab this from gamespark in my game but you can use a local variable you increment for every time they launch the app.
}
)
end
return true
end
Runtime:addEventListener( "system", onSystemEvent )