-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
73 lines (61 loc) · 2.88 KB
/
main.lua
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
print("CORONA: Start main.lua")
local json = require "json"
local composer = require "composer"
local OneSignal = require ("plugin.OneSignal")
-- show default status bar (iOS)
display.setStatusBar( display.DefaultStatusBar )
-- NOTIFICATION OPENED CALLBACK
-- This function gets called when the user opens a notification
function NotificationOpenedHandler(message, additionalData, isActive)
-- Easy way to dump table to string, not necessary to access contents
local additionalDataString = nil
if (additionalData) then
additionalDataString = json.encode( additionalData )
end
-- Print all of the handler params
print("Corona Notification Opened!" ..
" Notification Message: " .. tostring(message) ..
" Additional Date: " .. tostring(additionalDataString) ..
" Is Active: " .. tostring(isActive))
end
-- IAM CLICK ACTION CALLBACK
-- This function gets called when the user clicks on an IAM element
function InAppMessagedClickHandler(actionTable)
-- Print all of the handler params from the actionTable
print("In App Message Clicked!" ..
" Click Name: " .. tostring( actionTable['click_name'] ) ..
" Click Url: " .. tostring( actionTable['click_url'] ) ..
" First Click: " .. tostring( actionTable['first_click'] ) ..
" Closes Message: " .. tostring( actionTable['closes_message'] ))
end
-- GET TRIGGER VALUE FOR KEY CALLBACK
-- After the trigger value for an trigger key is received it is provided here with the corresponding key
function GetTriggerValueForKeyHandler(key, value)
-- Print the key, value pair from obtaining the trigger value
print("Obtained Trigger Value for Key!" ..
"Trigger Key, Value: " .. tostring( key ) .. ", " .. tostring( value ))
end
-- IAM PUBLIC METHODS
-- Example showcase of IAM methods for public usage in Corona
function ExampleInAppMessagingMethods()
-- Toggle showing of IAMs for the device
OneSignal.PauseInAppMessages(false)
-- Adding a single trigger, value pair or several at a time with a table
OneSignal.AddTrigger("trigger_1", "one")
local triggerTable = { ["trigger_2"] = "two", ["trigger_3"] = "three", ["trigger_4"] = "four" }
OneSignal.AddTriggers(triggerTable)
-- Removing a single trigger by key or removing several at a time with a table
OneSignal.RemoveTriggerForKey("trigger_4")
local removeTriggers = {"trigger_1", "trigger_2"}
OneSignal.RemoveTriggersForKeys(removeTriggers)
-- Getting a trigger's value by key and returning the key, value in a callback
OneSignal.GetTriggerValueForKey("trigger_2", GetTriggerValueForKeyHandler)
OneSignal.GetTriggerValueForKey("trigger_3", GetTriggerValueForKeyHandler)
end
-- START OF LUA SCRIPT
-- Replace with your AppId
OneSignal.Init("5eb5a37e-b458-11e3-ac11-000c2940e62c", "714322744251", NotificationOpenedHandler)
OneSignal.SetInAppMessageClickHandler(InAppMessagedClickHandler)
ExampleInAppMessagingMethods()
-- Go to view1 scene
composer.gotoScene( "view1" )