-
Notifications
You must be signed in to change notification settings - Fork 5
/
UrbanAirshipBehaviour.cs
111 lines (92 loc) · 3.9 KB
/
UrbanAirshipBehaviour.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Copyright Airship and Contributors */
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UrbanAirship;
public class UrbanAirshipBehaviour : MonoBehaviour {
public string addTagOnStart;
void Awake () {
UAirship.Shared.UserNotificationsEnabled = true;
}
void Start () {
if (!string.IsNullOrEmpty (addTagOnStart)) {
UAirship.Shared.AddTag (addTagOnStart);
}
string[] allenable = new string[] { "FEATURE_ALL" };
UAirship.Shared.SetEnabledFeatures(allenable);
UAirship.Shared.OnPushReceived += OnPushReceived;
UAirship.Shared.OnChannelUpdated += OnChannelUpdated;
UAirship.Shared.OnDeepLinkReceived += OnDeepLinkReceived;
UAirship.Shared.OnPushOpened += OnPushOpened;
UAirship.Shared.OnInboxUpdated += OnInboxUpdated;
UAirship.Shared.OnShowInbox += OnShowInbox;
UAirship.Shared.TrackScreen("Main Camera");
UAirship.Shared.RefreshInbox();
UAirship.Shared.EditChannelAttributes().SetAttribute("teststring", "a_string").Apply();
UAirship.Shared.EditChannelAttributes().SetAttribute("testint", (int) 1).Apply();
UAirship.Shared.EditChannelAttributes().SetAttribute("testlong", (long) 1000).Apply();
UAirship.Shared.EditChannelAttributes().SetAttribute("testfloat", (float)5.99).Apply();
UAirship.Shared.EditChannelAttributes().SetAttribute("testdouble", (double)5555.999).Apply();
UAirship.Shared.EditChannelAttributes().SetAttribute("testdate", DateTime.UtcNow).Apply();
}
void OnDestroy () {
UAirship.Shared.OnPushReceived -= OnPushReceived;
UAirship.Shared.OnChannelUpdated -= OnChannelUpdated;
UAirship.Shared.OnDeepLinkReceived -= OnDeepLinkReceived;
UAirship.Shared.OnPushOpened -= OnPushOpened;
}
void OnPushReceived (PushMessage message) {
Debug.Log ("Received push! " + message.Alert);
if (message.Extras != null) {
foreach (KeyValuePair<string, string> kvp in message.Extras) {
Debug.Log (string.Format ("Extras Key = {0}, Value = {1}", kvp.Key, kvp.Value));
}
}
}
void OnPushOpened (PushMessage message) {
Debug.Log ("Opened Push! " + message.Alert);
if (message.Extras != null) {
foreach (KeyValuePair<string, string> kvp in message.Extras) {
Debug.Log (string.Format ("Extras Key = {0}, Value = {1}", kvp.Key, kvp.Value));
}
}
}
void OnChannelUpdated (string channelId) {
Debug.Log ("Channel updated: " + channelId);
}
void OnDeepLinkReceived (string deeplink) {
Debug.Log ("Received deep link: " + deeplink);
}
void OnInboxUpdated (uint messageUnreadCount, uint messageCount)
{
Debug.Log("Inbox updated - unread messages: " + messageUnreadCount + " total messages: " + messageCount);
IEnumerable<InboxMessage>inboxMessages = UAirship.Shared.InboxMessages();
foreach (InboxMessage inboxMessage in inboxMessages)
{
Debug.Log("Message id: " + inboxMessage.id + ", title: " + inboxMessage.title + ", sentDate: " + inboxMessage.sentDate + ", isRead: " + inboxMessage.isRead + ", isDeleted: " + inboxMessage.isDeleted);
if (inboxMessage.extras == null)
{
Debug.Log("Extras is null");
}
else
{
foreach (KeyValuePair<string, string> entry in inboxMessage.extras)
{
Debug.Log("Message extras [" + entry.Key + "] = " + entry.Value);
}
}
}
}
void OnShowInbox (string messageId)
{
if (messageId == null)
{
Debug.Log("OnShowInbox - show inbox");
}
else
{
Debug.Log("OnShowInbox - show message: messageId = " + messageId);
}
}
}