|
1
|
import 'dart:async';
|
1
|
import 'dart:async';
|
|
2
|
import 'dart:convert';
|
2
|
import 'dart:convert';
|
|
3
|
|
3
|
|
|
4
|
-import 'package:fake_push/fake_push.dart' as fake;
|
4
|
+//import 'package:fake_push/fake_push.dart' as fake;
|
|
5
|
import 'package:flutter/cupertino.dart';
|
5
|
import 'package:flutter/cupertino.dart';
|
|
6
|
import 'package:flutter/material.dart';
|
6
|
import 'package:flutter/material.dart';
|
|
7
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
7
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
@@ -39,12 +39,12 @@ class HomePage extends StatefulWidget{ |
|
@@ -39,12 +39,12 @@ class HomePage extends StatefulWidget{ |
|
39
|
class HomePageState extends State<HomePage>{
|
39
|
class HomePageState extends State<HomePage>{
|
|
40
|
|
40
|
|
|
41
|
// 信鸽推送
|
41
|
// 信鸽推送
|
|
42
|
- fake.Push _push = fake.Push();
|
|
|
|
43
|
- StreamSubscription<String> _receiveDeviceToken;
|
|
|
|
44
|
- StreamSubscription<fake.Message> _receiveMessage;
|
|
|
|
45
|
- StreamSubscription<fake.Message> _receiveNotification;
|
|
|
|
46
|
- StreamSubscription<String> _launchNotification;
|
|
|
|
47
|
- StreamSubscription<String> _resumeNotification;
|
42
|
+// fake.Push _push = fake.Push();
|
|
|
|
43
|
+// StreamSubscription<String> _receiveDeviceToken;
|
|
|
|
44
|
+// StreamSubscription<fake.Message> _receiveMessage;
|
|
|
|
45
|
+// StreamSubscription<fake.Message> _receiveNotification;
|
|
|
|
46
|
+// StreamSubscription<String> _launchNotification;
|
|
|
|
47
|
+// StreamSubscription<String> _resumeNotification;
|
|
48
|
|
48
|
|
|
49
|
// 极光推送
|
49
|
// 极光推送
|
|
50
|
final JPush jpush = new JPush();
|
50
|
final JPush jpush = new JPush();
|
|
@@ -124,53 +124,53 @@ class HomePageState extends State<HomePage>{ |
|
@@ -124,53 +124,53 @@ class HomePageState extends State<HomePage>{ |
|
124
|
|
124
|
|
|
125
|
//初始化信鸽推送
|
125
|
//初始化信鸽推送
|
|
126
|
void initXinge(){
|
126
|
void initXinge(){
|
|
127
|
- _receiveDeviceToken =
|
|
|
|
128
|
- _push.receiveDeviceToken().listen(_handleReceiveDeviceToken);
|
|
|
|
129
|
- _receiveMessage = _push.receiveMessage().listen(_handleReceiveMessage);
|
|
|
|
130
|
- _receiveNotification =
|
|
|
|
131
|
- _push.receiveNotification().listen(_handleReceiveNotification);
|
|
|
|
132
|
- _launchNotification =
|
|
|
|
133
|
- _push.launchNotification().listen(_handleLaunchNotification);
|
|
|
|
134
|
- _resumeNotification =
|
|
|
|
135
|
- _push.resumeNotification().listen(_handleResumeNotification);
|
|
|
|
136
|
-
|
|
|
|
137
|
- _push.startWork(enableDebug: !_isReleaseMode());
|
|
|
|
138
|
-
|
|
|
|
139
|
- // 第二次打开应用再调用
|
|
|
|
140
|
- SharedPreferences.getInstance().then((SharedPreferences sharedPref) {
|
|
|
|
141
|
- if (sharedPref.getBool('firstStart') ?? true) {
|
|
|
|
142
|
- sharedPref.setBool('firstStart', false);
|
|
|
|
143
|
- } else {
|
|
|
|
144
|
- _push.areNotificationsEnabled().then((bool isEnabled) {
|
|
|
|
145
|
- if (!isEnabled) {
|
|
|
|
146
|
- showCupertinoDialog(
|
|
|
|
147
|
- context: context,
|
|
|
|
148
|
- builder: (BuildContext context) {
|
|
|
|
149
|
- return CupertinoAlertDialog(
|
|
|
|
150
|
- title: const Text('提示'),
|
|
|
|
151
|
- content: const Text('开启通知权限可收到更多优质内容'),
|
|
|
|
152
|
- actions: <Widget>[
|
|
|
|
153
|
- CupertinoDialogAction(
|
|
|
|
154
|
- child: const Text('取消'),
|
|
|
|
155
|
- onPressed: () {
|
|
|
|
156
|
- Navigator.of(context).pop();
|
|
|
|
157
|
- },
|
|
|
|
158
|
- ),
|
|
|
|
159
|
- CupertinoDialogAction(
|
|
|
|
160
|
- child: const Text('设置'),
|
|
|
|
161
|
- onPressed: () {
|
|
|
|
162
|
- _push.openNotificationsSettings();
|
|
|
|
163
|
- Navigator.of(context).pop();
|
|
|
|
164
|
- },
|
|
|
|
165
|
- ),
|
|
|
|
166
|
- ],
|
|
|
|
167
|
- );
|
|
|
|
168
|
- },
|
|
|
|
169
|
- );
|
|
|
|
170
|
- }
|
|
|
|
171
|
- });
|
|
|
|
172
|
- }
|
|
|
|
173
|
- });
|
127
|
+// _receiveDeviceToken =
|
|
|
|
128
|
+// _push.receiveDeviceToken().listen(_handleReceiveDeviceToken);
|
|
|
|
129
|
+// _receiveMessage = _push.receiveMessage().listen(_handleReceiveMessage);
|
|
|
|
130
|
+// _receiveNotification =
|
|
|
|
131
|
+// _push.receiveNotification().listen(_handleReceiveNotification);
|
|
|
|
132
|
+// _launchNotification =
|
|
|
|
133
|
+// _push.launchNotification().listen(_handleLaunchNotification);
|
|
|
|
134
|
+// _resumeNotification =
|
|
|
|
135
|
+// _push.resumeNotification().listen(_handleResumeNotification);
|
|
|
|
136
|
+//
|
|
|
|
137
|
+// _push.startWork(enableDebug: !_isReleaseMode());
|
|
|
|
138
|
+//
|
|
|
|
139
|
+// // 第二次打开应用再调用
|
|
|
|
140
|
+// SharedPreferences.getInstance().then((SharedPreferences sharedPref) {
|
|
|
|
141
|
+// if (sharedPref.getBool('firstStart') ?? true) {
|
|
|
|
142
|
+// sharedPref.setBool('firstStart', false);
|
|
|
|
143
|
+// } else {
|
|
|
|
144
|
+// _push.areNotificationsEnabled().then((bool isEnabled) {
|
|
|
|
145
|
+// if (!isEnabled) {
|
|
|
|
146
|
+// showCupertinoDialog(
|
|
|
|
147
|
+// context: context,
|
|
|
|
148
|
+// builder: (BuildContext context) {
|
|
|
|
149
|
+// return CupertinoAlertDialog(
|
|
|
|
150
|
+// title: const Text('提示'),
|
|
|
|
151
|
+// content: const Text('开启通知权限可收到更多优质内容'),
|
|
|
|
152
|
+// actions: <Widget>[
|
|
|
|
153
|
+// CupertinoDialogAction(
|
|
|
|
154
|
+// child: const Text('取消'),
|
|
|
|
155
|
+// onPressed: () {
|
|
|
|
156
|
+// Navigator.of(context).pop();
|
|
|
|
157
|
+// },
|
|
|
|
158
|
+// ),
|
|
|
|
159
|
+// CupertinoDialogAction(
|
|
|
|
160
|
+// child: const Text('设置'),
|
|
|
|
161
|
+// onPressed: () {
|
|
|
|
162
|
+// _push.openNotificationsSettings();
|
|
|
|
163
|
+// Navigator.of(context).pop();
|
|
|
|
164
|
+// },
|
|
|
|
165
|
+// ),
|
|
|
|
166
|
+// ],
|
|
|
|
167
|
+// );
|
|
|
|
168
|
+// },
|
|
|
|
169
|
+// );
|
|
|
|
170
|
+// }
|
|
|
|
171
|
+// });
|
|
|
|
172
|
+// }
|
|
|
|
173
|
+// });
|
|
174
|
}
|
174
|
}
|
|
175
|
|
175
|
|
|
176
|
bool _isReleaseMode() {
|
176
|
bool _isReleaseMode() {
|
|
@@ -178,31 +178,31 @@ class HomePageState extends State<HomePage>{ |
|
@@ -178,31 +178,31 @@ class HomePageState extends State<HomePage>{ |
|
178
|
}
|
178
|
}
|
|
179
|
|
179
|
|
|
180
|
void _handleReceiveDeviceToken(String deviceToken) async {
|
180
|
void _handleReceiveDeviceToken(String deviceToken) async {
|
|
181
|
- String token=await _push.getDeviceToken();
|
|
|
|
182
|
- print('receiveDeviceToken: $deviceToken - $token');
|
|
|
|
183
|
- userTokenInit2(token);
|
|
|
|
184
|
- }
|
|
|
|
185
|
-
|
|
|
|
186
|
- void _handleReceiveMessage(fake.Message message) {
|
|
|
|
187
|
- print(
|
|
|
|
188
|
- 'receiveMessage: ${message.title} - ${message.content} - ${message.customContent}');
|
181
|
+// String token=await _push.getDeviceToken();
|
|
|
|
182
|
+// print('receiveDeviceToken: $deviceToken - $token');
|
|
|
|
183
|
+// userTokenInit2(token);
|
|
189
|
}
|
184
|
}
|
|
190
|
|
185
|
|
|
191
|
- void _handleReceiveNotification(fake.Message notification) {
|
|
|
|
192
|
- print(
|
|
|
|
193
|
- 'receiveNotification: ${notification.title} - ${notification.content} - ${notification.customContent}');
|
|
|
|
194
|
-
|
|
|
|
195
|
- }
|
|
|
|
196
|
-
|
|
|
|
197
|
- void _handleLaunchNotification(String customContent) {
|
|
|
|
198
|
- print('launchNotification: $customContent');
|
|
|
|
199
|
-
|
|
|
|
200
|
- }
|
|
|
|
201
|
-
|
|
|
|
202
|
- void _handleResumeNotification(String customContent) {
|
|
|
|
203
|
- print('resumeNotification: $customContent');
|
|
|
|
204
|
-
|
|
|
|
205
|
- }
|
186
|
+// void _handleReceiveMessage(fake.Message message) {
|
|
|
|
187
|
+// print(
|
|
|
|
188
|
+// 'receiveMessage: ${message.title} - ${message.content} - ${message.customContent}');
|
|
|
|
189
|
+// }
|
|
|
|
190
|
+//
|
|
|
|
191
|
+// void _handleReceiveNotification(fake.Message notification) {
|
|
|
|
192
|
+// print(
|
|
|
|
193
|
+// 'receiveNotification: ${notification.title} - ${notification.content} - ${notification.customContent}');
|
|
|
|
194
|
+//
|
|
|
|
195
|
+// }
|
|
|
|
196
|
+//
|
|
|
|
197
|
+// void _handleLaunchNotification(String customContent) {
|
|
|
|
198
|
+// print('launchNotification: $customContent');
|
|
|
|
199
|
+//
|
|
|
|
200
|
+// }
|
|
|
|
201
|
+//
|
|
|
|
202
|
+// void _handleResumeNotification(String customContent) {
|
|
|
|
203
|
+// print('resumeNotification: $customContent');
|
|
|
|
204
|
+//
|
|
|
|
205
|
+// }
|
|
206
|
|
206
|
|
|
207
|
//初始化推送token
|
207
|
//初始化推送token
|
|
208
|
userTokenInit(String registrationId){
|
208
|
userTokenInit(String registrationId){
|
|
@@ -326,21 +326,21 @@ class HomePageState extends State<HomePage>{ |
|
@@ -326,21 +326,21 @@ class HomePageState extends State<HomePage>{ |
|
326
|
@override
|
326
|
@override
|
|
327
|
void dispose() {
|
327
|
void dispose() {
|
|
328
|
// TODO: implement dispose
|
328
|
// TODO: implement dispose
|
|
329
|
- if (_receiveDeviceToken != null) {
|
|
|
|
330
|
- _receiveDeviceToken.cancel();
|
|
|
|
331
|
- }
|
|
|
|
332
|
- if (_receiveMessage != null) {
|
|
|
|
333
|
- _receiveMessage.cancel();
|
|
|
|
334
|
- }
|
|
|
|
335
|
- if (_receiveNotification != null) {
|
|
|
|
336
|
- _receiveNotification.cancel();
|
|
|
|
337
|
- }
|
|
|
|
338
|
- if (_launchNotification != null) {
|
|
|
|
339
|
- _launchNotification.cancel();
|
|
|
|
340
|
- }
|
|
|
|
341
|
- if (_resumeNotification != null) {
|
|
|
|
342
|
- _resumeNotification.cancel();
|
|
|
|
343
|
- }
|
329
|
+// if (_receiveDeviceToken != null) {
|
|
|
|
330
|
+// _receiveDeviceToken.cancel();
|
|
|
|
331
|
+// }
|
|
|
|
332
|
+// if (_receiveMessage != null) {
|
|
|
|
333
|
+// _receiveMessage.cancel();
|
|
|
|
334
|
+// }
|
|
|
|
335
|
+// if (_receiveNotification != null) {
|
|
|
|
336
|
+// _receiveNotification.cancel();
|
|
|
|
337
|
+// }
|
|
|
|
338
|
+// if (_launchNotification != null) {
|
|
|
|
339
|
+// _launchNotification.cancel();
|
|
|
|
340
|
+// }
|
|
|
|
341
|
+// if (_resumeNotification != null) {
|
|
|
|
342
|
+// _resumeNotification.cancel();
|
|
|
|
343
|
+// }
|
|
344
|
super.dispose();
|
344
|
super.dispose();
|
|
345
|
LogUtil.v("home_dispose");
|
345
|
LogUtil.v("home_dispose");
|
|
346
|
}
|
346
|
}
|