-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushBehaviour.cs
69 lines (50 loc) · 1.54 KB
/
PushBehaviour.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
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class PushBehaviour : MonoBehaviour {
string deviceToken = String.Empty;
bool tokenSent = false;
void Start ()
{
Debug.Log( "Registering for push notifications" );
NotificationServices.RegisterForRemoteNotificationTypes( RemoteNotificationType.Alert
| RemoteNotificationType.Badge | RemoteNotificationType.Sound );
}
RemoteNotification lastNotification;
void Update ()
{
if ( !tokenSent )
{
var token = NotificationServices.deviceToken;
if ( token != null )
{
tokenSent = true;
deviceToken = System.BitConverter.ToString( token ).Replace("-","");
Debug.Log( "Device Token: " + deviceToken );
}
}
if( NotificationServices.remoteNotificationCount > 0)
{
lastNotification = NotificationServices.remoteNotifications[0];
Debug.Log("AlertBody " + lastNotification.alertBody);
Debug.Log("UserInfo " + lastNotification.userInfo);
NotificationServices.ClearRemoteNotifications();
}
}
void OnGUI()
{
GUILayout.BeginVertical();
GUILayout.Label(string.Format("Device Token: {0}", deviceToken));
if( lastNotification != null )
{
GUILayout.Label(string.Format("AlertBody: {0}", lastNotification.alertBody));
GUILayout.Label(string.Format("UserInfo:"));
foreach(var key in lastNotification.userInfo.Keys )
{
GUILayout.Label(string.Format("{0}: {1}", key, lastNotification.userInfo[key]));
}
}
GUILayout.EndVertical();
}
}