|
@@ -3,6 +3,7 @@ import 'dart:io'; |
|
@@ -3,6 +3,7 @@ import 'dart:io'; |
|
3
|
import 'package:flutter/cupertino.dart';
|
3
|
import 'package:flutter/cupertino.dart';
|
|
4
|
import 'package:flutter/material.dart';
|
4
|
import 'package:flutter/material.dart';
|
|
5
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
5
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
6
|
+import 'package:one_key/app.dart';
|
|
6
|
import 'package:one_key/pages/message/message_page.dart';
|
7
|
import 'package:one_key/pages/message/message_page.dart';
|
|
7
|
import 'package:one_key/pages/my/my_page.dart';
|
8
|
import 'package:one_key/pages/my/my_page.dart';
|
|
8
|
import 'package:one_key/pages/notebook/notebook_page.dart';
|
9
|
import 'package:one_key/pages/notebook/notebook_page.dart';
|
|
@@ -43,6 +44,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -43,6 +44,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
43
|
|
44
|
|
|
44
|
Timer timer;
|
45
|
Timer timer;
|
|
45
|
|
46
|
|
|
|
|
47
|
+ int xgCount=1;//注册信鸽次数,最多5次
|
|
|
|
48
|
+
|
|
46
|
@override
|
49
|
@override
|
|
47
|
void initState() {
|
50
|
void initState() {
|
|
48
|
// TODO: implement initState
|
51
|
// TODO: implement initState
|
|
@@ -65,7 +68,10 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -65,7 +68,10 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
65
|
));
|
68
|
));
|
|
66
|
WidgetsBinding.instance.addPostFrameCallback((_){
|
69
|
WidgetsBinding.instance.addPostFrameCallback((_){
|
|
67
|
if(widget.initialIndex==0)return;
|
70
|
if(widget.initialIndex==0)return;
|
|
68
|
- ContactModel.getInstance().uploadLocalContact(context);
|
71
|
+ initPlatformState();
|
|
|
|
72
|
+ Future.delayed(Duration(milliseconds: 30000),(){
|
|
|
|
73
|
+ ContactModel.getInstance().uploadLocalContact(context);
|
|
|
|
74
|
+ });
|
|
69
|
getUntreatedMessage();
|
75
|
getUntreatedMessage();
|
|
70
|
timer=Timer.periodic(Duration(minutes: 3), (_){
|
76
|
timer=Timer.periodic(Duration(minutes: 3), (_){
|
|
71
|
getUntreatedMessage();
|
77
|
getUntreatedMessage();
|
|
@@ -73,16 +79,10 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -73,16 +79,10 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
73
|
UpdateModel updateModel=new UpdateModel();
|
79
|
UpdateModel updateModel=new UpdateModel();
|
|
74
|
updateModel.checkUpdate(context,showToast: false);
|
80
|
updateModel.checkUpdate(context,showToast: false);
|
|
75
|
});
|
81
|
});
|
|
76
|
- initPlatformState();
|
|
|
|
77
|
-
|
|
|
|
78
|
}
|
82
|
}
|
|
79
|
|
83
|
|
|
80
|
//初始化信鸽推送
|
84
|
//初始化信鸽推送
|
|
81
|
- Future<void> initPlatformState() async {
|
|
|
|
82
|
- // If the widget was removed from the tree while the asynchronous platform
|
|
|
|
83
|
- // message was in flight, we want to discard the reply rather than calling
|
|
|
|
84
|
- // setState to update our non-existent appearance.
|
|
|
|
85
|
- if (!mounted) return;
|
85
|
+ initPlatformState(){
|
|
86
|
|
86
|
|
|
87
|
/// 开启DEBUG
|
87
|
/// 开启DEBUG
|
|
88
|
XgFlutterPlugin().setEnableDebug(true);
|
88
|
XgFlutterPlugin().setEnableDebug(true);
|
|
@@ -93,10 +93,21 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -93,10 +93,21 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
93
|
print("flutter onRegisteredDeviceToken: $msg");
|
93
|
print("flutter onRegisteredDeviceToken: $msg");
|
|
94
|
},
|
94
|
},
|
|
95
|
onRegisteredDone: (String msg) async {
|
95
|
onRegisteredDone: (String msg) async {
|
|
96
|
- print("flutter onRegisteredDone: $msg");
|
|
|
|
97
|
- LogUtil.v("注册成功");
|
|
|
|
98
|
- if(msg.isNotEmpty){
|
|
|
|
99
|
- userTokenInit(msg);
|
96
|
+ String token="";
|
|
|
|
97
|
+ try{
|
|
|
|
98
|
+ token=await XgFlutterPlugin.xgToken;
|
|
|
|
99
|
+ }catch(e){
|
|
|
|
100
|
+ LogUtil.v("注册失败:${e.toString()}");
|
|
|
|
101
|
+// Utils.showToast("注册失败:${e.toString()}");
|
|
|
|
102
|
+ }
|
|
|
|
103
|
+ if(token==null||token.isEmpty){
|
|
|
|
104
|
+ LogUtil.v("注册失败:${xgCount.toString()}");
|
|
|
|
105
|
+// Utils.showToast("注册失败:${xgCount.toString()}");
|
|
|
|
106
|
+ registerPush();
|
|
|
|
107
|
+ }else{
|
|
|
|
108
|
+ LogUtil.v("注册成功:$token");
|
|
|
|
109
|
+// Utils.showToast("注册成功:$token");
|
|
|
|
110
|
+ userTokenInit(token);
|
|
100
|
}
|
111
|
}
|
|
101
|
},
|
112
|
},
|
|
102
|
unRegistered: (String msg) async {
|
113
|
unRegistered: (String msg) async {
|
|
@@ -110,7 +121,6 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -110,7 +121,6 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
110
|
},
|
121
|
},
|
|
111
|
xgPushDidSetBadge: (String msg) async {
|
122
|
xgPushDidSetBadge: (String msg) async {
|
|
112
|
print("flutter xgPushDidSetBadge: $msg");
|
123
|
print("flutter xgPushDidSetBadge: $msg");
|
|
113
|
-
|
|
|
|
114
|
/// 在此可设置应用角标
|
124
|
/// 在此可设置应用角标
|
|
115
|
/// XgFlutterPlugin().setAppBadge(0);;
|
125
|
/// XgFlutterPlugin().setAppBadge(0);;
|
|
116
|
},
|
126
|
},
|
|
@@ -130,29 +140,30 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -130,29 +140,30 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
130
|
print("flutter xgPushClickAction $msg");
|
140
|
print("flutter xgPushClickAction $msg");
|
|
131
|
},
|
141
|
},
|
|
132
|
);
|
142
|
);
|
|
|
|
143
|
+ registerPush();
|
|
|
|
144
|
+ }
|
|
133
|
|
145
|
|
|
134
|
- /// 如果您的应用非广州集群则需要在startXG之前调用此函数
|
|
|
|
135
|
- /// 香港:tpns.hk.tencent.com
|
|
|
|
136
|
- /// 新加坡:tpns.sgp.tencent.com
|
|
|
|
137
|
- /// 上海:tpns.sh.tencent.com
|
|
|
|
138
|
- // XgFlutterPlugin().configureClusterDomainName("tpns.hk.tencent.com");
|
|
|
|
139
|
-
|
146
|
+ //注册信鸽
|
|
|
|
147
|
+ registerPush() async {
|
|
|
|
148
|
+ if(xgCount>5)return;
|
|
140
|
if(Platform.isAndroid){
|
149
|
if(Platform.isAndroid){
|
|
141
|
/// 设置OPPO AppKey 和 AppSecret
|
150
|
/// 设置OPPO AppKey 和 AppSecret
|
|
142
|
if(await XgFlutterPlugin().getXgAndroidApi().isOppoRom()){
|
151
|
if(await XgFlutterPlugin().getXgAndroidApi().isOppoRom()){
|
|
143
|
- XgFlutterPlugin().getXgAndroidApi().enableOppoNotification();
|
|
|
|
144
|
- XgFlutterPlugin().getXgAndroidApi().setOppoPushAppId(appId:"30260281");
|
|
|
|
145
|
- XgFlutterPlugin().getXgAndroidApi().setOppoPushAppKey(appKey: "9b7e372f93794593953f93f118619570");
|
|
|
|
146
|
- }
|
|
|
|
147
|
- // 设置小米 AppID 和 AppKey。
|
|
|
|
148
|
- if(await XgFlutterPlugin().getXgAndroidApi().isMiuiRom()){
|
|
|
|
149
|
- XgFlutterPlugin().getXgAndroidApi().setMiPushAppId(appId:"2882303761518639456");
|
|
|
|
150
|
- XgFlutterPlugin().getXgAndroidApi().setMiPushAppKey(appKey: "5231863961456");
|
|
|
|
151
|
- }
|
|
|
|
152
|
- XgFlutterPlugin().getXgAndroidApi().enableOtherPush();
|
152
|
+ XgFlutterPlugin().getXgAndroidApi().enableOppoNotification();
|
|
|
|
153
|
+ XgFlutterPlugin().getXgAndroidApi().setOppoPushAppId(appId:"30260281");
|
|
|
|
154
|
+ XgFlutterPlugin().getXgAndroidApi().setOppoPushAppKey(appKey: "9b7e372f93794593953f93f118619570");
|
|
|
|
155
|
+ }
|
|
|
|
156
|
+ // 设置小米 AppID 和 AppKey。
|
|
|
|
157
|
+ if(await XgFlutterPlugin().getXgAndroidApi().isMiuiRom()){
|
|
|
|
158
|
+ XgFlutterPlugin().getXgAndroidApi().setMiPushAppId(appId:"2882303761518639456");
|
|
|
|
159
|
+ XgFlutterPlugin().getXgAndroidApi().setMiPushAppKey(appKey: "5231863961456");
|
|
|
|
160
|
+ }
|
|
|
|
161
|
+ XgFlutterPlugin().getXgAndroidApi().enableOtherPush();
|
|
153
|
}
|
162
|
}
|
|
154
|
/// 启动TPNS服务
|
163
|
/// 启动TPNS服务
|
|
|
|
164
|
+ LogUtil.v("register:${xgCount.toString()}");
|
|
155
|
XgFlutterPlugin().startXg("1600012876", "INUIMFK21WGH");
|
165
|
XgFlutterPlugin().startXg("1600012876", "INUIMFK21WGH");
|
|
|
|
166
|
+ xgCount++;
|
|
156
|
}
|
167
|
}
|
|
157
|
|
168
|
|
|
158
|
|
169
|
|
|
@@ -284,5 +295,6 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
@@ -284,5 +295,6 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
284
|
}
|
295
|
}
|
|
285
|
XgFlutterPlugin().stopXg();
|
296
|
XgFlutterPlugin().stopXg();
|
|
286
|
WidgetsBinding.instance.removeObserver(this);
|
297
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
298
|
+
|
|
287
|
}
|
299
|
}
|
|
288
|
} |
300
|
} |