|
...
|
...
|
@@ -3,6 +3,7 @@ import 'dart:io'; |
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:one_key/app.dart';
|
|
|
|
import 'package:one_key/pages/message/message_page.dart';
|
|
|
|
import 'package:one_key/pages/my/my_page.dart';
|
|
|
|
import 'package:one_key/pages/notebook/notebook_page.dart';
|
|
...
|
...
|
@@ -43,6 +44,8 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
|
|
|
|
Timer timer;
|
|
|
|
|
|
|
|
int xgCount=1;//注册信鸽次数,最多5次
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
...
|
...
|
@@ -65,7 +68,10 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
));
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_){
|
|
|
|
if(widget.initialIndex==0)return;
|
|
|
|
ContactModel.getInstance().uploadLocalContact(context);
|
|
|
|
initPlatformState();
|
|
|
|
Future.delayed(Duration(milliseconds: 30000),(){
|
|
|
|
ContactModel.getInstance().uploadLocalContact(context);
|
|
|
|
});
|
|
|
|
getUntreatedMessage();
|
|
|
|
timer=Timer.periodic(Duration(minutes: 3), (_){
|
|
|
|
getUntreatedMessage();
|
|
...
|
...
|
@@ -73,16 +79,10 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
UpdateModel updateModel=new UpdateModel();
|
|
|
|
updateModel.checkUpdate(context,showToast: false);
|
|
|
|
});
|
|
|
|
initPlatformState();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//初始化信鸽推送
|
|
|
|
Future<void> initPlatformState() async {
|
|
|
|
// If the widget was removed from the tree while the asynchronous platform
|
|
|
|
// message was in flight, we want to discard the reply rather than calling
|
|
|
|
// setState to update our non-existent appearance.
|
|
|
|
if (!mounted) return;
|
|
|
|
initPlatformState(){
|
|
|
|
|
|
|
|
/// 开启DEBUG
|
|
|
|
XgFlutterPlugin().setEnableDebug(true);
|
|
...
|
...
|
@@ -93,10 +93,21 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
print("flutter onRegisteredDeviceToken: $msg");
|
|
|
|
},
|
|
|
|
onRegisteredDone: (String msg) async {
|
|
|
|
print("flutter onRegisteredDone: $msg");
|
|
|
|
LogUtil.v("注册成功");
|
|
|
|
if(msg.isNotEmpty){
|
|
|
|
userTokenInit(msg);
|
|
|
|
String token="";
|
|
|
|
try{
|
|
|
|
token=await XgFlutterPlugin.xgToken;
|
|
|
|
}catch(e){
|
|
|
|
LogUtil.v("注册失败:${e.toString()}");
|
|
|
|
// Utils.showToast("注册失败:${e.toString()}");
|
|
|
|
}
|
|
|
|
if(token==null||token.isEmpty){
|
|
|
|
LogUtil.v("注册失败:${xgCount.toString()}");
|
|
|
|
// Utils.showToast("注册失败:${xgCount.toString()}");
|
|
|
|
registerPush();
|
|
|
|
}else{
|
|
|
|
LogUtil.v("注册成功:$token");
|
|
|
|
// Utils.showToast("注册成功:$token");
|
|
|
|
userTokenInit(token);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unRegistered: (String msg) async {
|
|
...
|
...
|
@@ -110,7 +121,6 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
},
|
|
|
|
xgPushDidSetBadge: (String msg) async {
|
|
|
|
print("flutter xgPushDidSetBadge: $msg");
|
|
|
|
|
|
|
|
/// 在此可设置应用角标
|
|
|
|
/// XgFlutterPlugin().setAppBadge(0);;
|
|
|
|
},
|
|
...
|
...
|
@@ -130,29 +140,30 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
print("flutter xgPushClickAction $msg");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
registerPush();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 如果您的应用非广州集群则需要在startXG之前调用此函数
|
|
|
|
/// 香港:tpns.hk.tencent.com
|
|
|
|
/// 新加坡:tpns.sgp.tencent.com
|
|
|
|
/// 上海:tpns.sh.tencent.com
|
|
|
|
// XgFlutterPlugin().configureClusterDomainName("tpns.hk.tencent.com");
|
|
|
|
|
|
|
|
//注册信鸽
|
|
|
|
registerPush() async {
|
|
|
|
if(xgCount>5)return;
|
|
|
|
if(Platform.isAndroid){
|
|
|
|
/// 设置OPPO AppKey 和 AppSecret
|
|
|
|
if(await XgFlutterPlugin().getXgAndroidApi().isOppoRom()){
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().enableOppoNotification();
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setOppoPushAppId(appId:"30260281");
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setOppoPushAppKey(appKey: "9b7e372f93794593953f93f118619570");
|
|
|
|
}
|
|
|
|
// 设置小米 AppID 和 AppKey。
|
|
|
|
if(await XgFlutterPlugin().getXgAndroidApi().isMiuiRom()){
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setMiPushAppId(appId:"2882303761518639456");
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setMiPushAppKey(appKey: "5231863961456");
|
|
|
|
}
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().enableOtherPush();
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().enableOppoNotification();
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setOppoPushAppId(appId:"30260281");
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setOppoPushAppKey(appKey: "9b7e372f93794593953f93f118619570");
|
|
|
|
}
|
|
|
|
// 设置小米 AppID 和 AppKey。
|
|
|
|
if(await XgFlutterPlugin().getXgAndroidApi().isMiuiRom()){
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setMiPushAppId(appId:"2882303761518639456");
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().setMiPushAppKey(appKey: "5231863961456");
|
|
|
|
}
|
|
|
|
XgFlutterPlugin().getXgAndroidApi().enableOtherPush();
|
|
|
|
}
|
|
|
|
/// 启动TPNS服务
|
|
|
|
LogUtil.v("register:${xgCount.toString()}");
|
|
|
|
XgFlutterPlugin().startXg("1600012876", "INUIMFK21WGH");
|
|
|
|
xgCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -284,5 +295,6 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver{ |
|
|
|
}
|
|
|
|
XgFlutterPlugin().stopXg();
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|