forked from moto2002/mobahero_src
/
APush.cs
154 lines (128 loc) · 3.48 KB
/
APush.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using JPush;
using System;
using UnityEngine;
public class APush : MonoBehaviour
{
private static string iosKey = "IOSToken";
private static string iosReg = "IOSRegId";
private static string andKey = "JPushID";
public static string regId = string.Empty;
public static string iosToken = string.Empty;
public string msg = string.Empty;
private static APush andriodOne;
private string str_unity = string.Empty;
private bool B_MESSAGE;
private static string str_message = string.Empty;
public static void StopAndriodPush()
{
if (APush.andriodOne != null)
{
APush.andriodOne.stopJPush(null);
}
}
public static void ResumeAndriodPush()
{
if (APush.andriodOne != null)
{
APush.andriodOne.resumeJPush(null);
}
}
private void Start()
{
APush.andriodOne = this;
if (PlayerPrefs.HasKey(APush.andKey))
{
APush.regId = PlayerPrefs.GetString(APush.andKey);
}
try
{
JPushBinding.setDebug(true);
JPushBinding.initJPush(base.gameObject.name, "InitOK");
JPushEventManager.instance.addEventListener(CustomEventObj.EVENT_INIT_JPUSH, base.gameObject, "initJPush");
JPushEventManager.instance.addEventListener(CustomEventObj.EVENT_STOP_JPUSH, base.gameObject, "stopJPush");
JPushEventManager.instance.addEventListener(CustomEventObj.EVENT_RESUME_JPUSH, base.gameObject, "resumeJPush");
JPushEventManager.instance.addEventListener(CustomEventObj.EVENT_SET_TAGS, base.gameObject, "setTags");
JPushEventManager.instance.addEventListener(CustomEventObj.EVENT_SET_ALIAS, base.gameObject, "setAlias");
JPushBinding.getRegistrationId(base.gameObject.name, "onGetRegId");
}
catch (Exception ex)
{
this.msg = ex.ToString();
}
}
private void InitOK()
{
MonoBehaviour.print("unity3d---InitOK");
}
private void OnDestroy()
{
MonoBehaviour.print("unity3d---onDestroy");
if (base.gameObject)
{
JPushEventManager.instance.removeAllEventListeners(base.gameObject);
}
}
private void initJPush(CustomEventObj evt)
{
JPushBinding.initJPush(base.gameObject.name, string.Empty);
}
private void setTags(CustomEventObj evt)
{
string tags = (string)evt.arguments["tags"];
JPushBinding.setTags(tags);
}
private void setAlias(CustomEventObj evt)
{
string alias = (string)evt.arguments["alias"];
JPushBinding.setAlias(alias);
}
private void setPushTime(CustomEventObj evt)
{
string days = (string)evt.arguments["days"];
int startHour = (int)evt.arguments["start_time"];
int endHour = (int)evt.arguments["end_time"];
JPushBinding.setPushTime(days, startHour, endHour);
}
private void recvMessage(string str)
{
this.B_MESSAGE = true;
APush.str_message = str;
this.str_unity = "有新消息";
this.msg = str;
}
private void openNotification(string str)
{
this.str_unity = str;
this.msg = str;
}
private void onGetRegId(string str)
{
if (!string.IsNullOrEmpty(str))
{
APush.regId = str;
PlayerPrefs.SetString(APush.andKey, APush.regId);
PlayerPrefs.Save();
}
}
private void onRegister(string str)
{
if (!string.IsNullOrEmpty(str))
{
APush.regId = str;
PlayerPrefs.SetString(APush.andKey, APush.regId);
PlayerPrefs.Save();
}
}
private void beforeQuit()
{
JPushBinding.isQuit();
}
private void stopJPush(CustomEventObj evt)
{
JPushBinding.stopJPush();
}
private void resumeJPush(CustomEventObj evt)
{
JPushBinding.resumeJPush();
}
}