28
28
添加事件监听方法。
29
29
30
30
``` dart
31
- JPush.addEventHandler(
31
+ JPush jpush = new JPush();
32
+ jpush.addEventHandler(
32
33
// 接收通知回调方法。
33
34
onReceiveNotification: (Map<String, dynamic> message) async {
34
35
print("flutter onReceiveNotification: $message");
@@ -52,7 +53,8 @@ JPush.addEventHandler(
52
53
- 将缓存的事件下发到 dart 环境中。
53
54
54
55
``` dart
55
- JPush.setup(
56
+ JPush jpush = new JPush();
57
+ jpush.setup(
56
58
appKey: "替换成你自己的 appKey",
57
59
channel: "theChannel",
58
60
production: false
@@ -64,79 +66,88 @@ JPush.setup(
64
66
获取 registrationId,这个 JPush 运行通过 registrationId 来进行推送.
65
67
66
68
``` dart
67
- JPush.getRegistrationID().then((rid) { });
69
+ JPush jpush = new JPush();
70
+ jpush.getRegistrationID().then((rid) { });
68
71
```
69
72
70
73
#### stopPush
71
74
72
75
停止推送功能,调用该方法将不会接收到通知。
73
76
74
77
``` dart
75
- JPush.stopPush();
78
+ JPush jpush = new JPush();
79
+ jpush.stopPush();
76
80
```
77
81
78
82
#### resumePush
79
83
80
84
调用 stopPush 后,可以通过 resumePush 方法恢复推送。
81
85
82
86
``` dart
83
- JPush.resumePush();
87
+ JPush jpush = new JPush();
88
+ jpush.resumePush();
84
89
```
85
90
86
91
#### setAlias
87
92
88
93
设置别名,极光后台可以通过别名来推送,一个 App 应用只有一个别名,一般用来存储用户 id。
89
94
90
95
```
91
- JPush.setAlias("your alias").then((map) { });
96
+ JPush jpush = new JPush();
97
+ jpush.setAlias("your alias").then((map) { });
92
98
```
93
99
94
100
#### deleteAlias
95
101
96
102
可以通过 deleteAlias 方法来删除已经设置的 alias。
97
103
98
104
``` dart
99
- JPush.deleteAlias().then((map) {})
105
+ JPush jpush = new JPush();
106
+ jpush.deleteAlias().then((map) {})
100
107
```
101
108
102
109
#### addTags
103
110
104
111
在原来的 Tags 列表上添加指定 tags。
105
112
106
113
```
107
- JPush.addTags(["tag1","tag2"]).then((map) {});
114
+ JPush jpush = new JPush();
115
+ jpush.addTags(["tag1","tag2"]).then((map) {});
108
116
```
109
117
110
118
#### deleteTags
111
119
112
120
在原来的 Tags 列表上删除指定 tags。
113
121
114
122
```
115
- JPush.deleteTags(["tag1","tag2"]).then((map) {});
123
+ JPush jpush = new JPush();
124
+ jpush.deleteTags(["tag1","tag2"]).then((map) {});
116
125
```
117
126
118
127
#### setTags
119
128
120
129
重置 tags。
121
130
122
- ```
123
- JPush.setTags(["tag1","tag2"]).then((map) {});
131
+ ``` dart
132
+ JPush jpush = new JPush();
133
+ jpush.setTags(["tag1","tag2"]).then((map) {});
124
134
```
125
135
126
136
#### cleanTags
127
137
128
138
清空所有 tags
129
139
130
140
``` dart
131
- JPush .setTags().then((map) {});
141
+ jpush .setTags().then((map) {});
132
142
```
133
143
134
144
#### getAllTags
135
145
136
146
获取当前 tags 列表。
137
147
138
- ```
139
- JPush.getAllTags().then((map) {});
148
+ ``` dart
149
+ JPush jpush = new JPush();
150
+ jpush.getAllTags().then((map) {});
140
151
```
141
152
142
153
#### sendLocalNotification
@@ -145,6 +156,7 @@ JPush.getAllTags().then((map) {});
145
156
146
157
``` dart
147
158
// 延时 3 秒后触发本地通知。
159
+ JPush jpush = new JPush();
148
160
var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000);
149
161
var localNotification = LocalNotification(
150
162
id: 234,
@@ -156,15 +168,16 @@ var localNotification = LocalNotification(
156
168
badge: 5, // 该参数只有在 iOS 有效
157
169
extras: {"fa": "0"} // 设置 extras ,extras 需要是 Map<String, String>
158
170
);
159
- JPush .sendLocalNotification(localNotification).then((res) {});
171
+ jpush .sendLocalNotification(localNotification).then((res) {});
160
172
```
161
173
162
174
#### clearAllNotifications
163
175
164
176
清楚通知栏上所有通知。
165
177
166
178
``` dart
167
- JPush.clearAllNotifications();
179
+ JPush jpush = new JPush();
180
+ jpush.clearAllNotifications();
168
181
```
169
182
170
183
#### applyPushAuthority
@@ -174,7 +187,8 @@ JPush.clearAllNotifications();
174
187
** 注意: iOS10+ 可以通过该方法来设置推送是否前台展示,是否触发声音,是否设置应用角标 badge**
175
188
176
189
``` dart
177
- JPush.applyPushAuthority(new NotificationSettingsIOS(
190
+ JPush jpush = new JPush();
191
+ jpush.applyPushAuthority(new NotificationSettingsIOS(
178
192
sound: true,
179
193
alert: true,
180
194
badge: true));
@@ -187,14 +201,16 @@ JPush.applyPushAuthority(new NotificationSettingsIOS(
187
201
设置应用 badge 值,该方法还会同步 JPush 服务器的的 badge 值,JPush 服务器的 badge 值用于推送 badge 自动 +1 时会用到。
188
202
189
203
``` dart
190
- JPush.setBadge(66).then((map) {});
204
+ JPush jpush = new JPush();
205
+ jpush.setBadge(66).then((map) {});
191
206
```
192
207
193
208
### getLaunchAppNotification
194
209
195
210
获取 iOS 点击推送启动应用的那条通知。
196
211
197
212
``` dart
198
- JPush.getLaunchAppNotification().then((map) {});
213
+ JPush jpush = new JPush();
214
+ jpush.getLaunchAppNotification().then((map) {});
199
215
```
200
216
0 commit comments