Commit 555226514f21a623cd089c44bdaf7ddd9de01010

Authored by gaiyaguang
1 parent 67173141

2020/05/11 10:25

... ... @@ -49,7 +49,7 @@ android {
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a'
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
manifestPlaceholders = [
... ... @@ -65,6 +65,16 @@ android {
// VIVO_APPKEY : "5811835841457", // VIVO平台注册的appkey
// VIVO_APPID : "2882303761518358457", // VIVO平台注册的appid
]
// manifestPlaceholders = [
// XG_ACCESS_ID : '2100332241',
// XG_ACCESS_KEY : 'A51T8RX1HS1W',
// XG_ACCESS_SCHEME: 'fake_push',// 非官方参数,可自定义,统一打开方式为 intent
// HW_APPID : '100728875',
// XIAOMI_APPID : '2882303761517989384',
// XIAOMI_APPKEY : '5141798993384',
// PACKAGE_NAME : "${applicationId}",// 小米通道
// ]
}
signingConfigs {
... ...
import 'dart:async';
import 'dart:convert';
import 'package:fake_push/fake_push.dart' as fake;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:one_key/app.dart';
import 'package:one_key/models/message.dart';
import 'package:one_key/pages/message/message_page.dart';
import 'package:one_key/pages/my/my_page.dart';
... ... @@ -15,12 +16,12 @@ import 'package:one_key/provider/my_model.dart';
import 'package:one_key/provider/notebook_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/route/navigate_service.dart';
import 'package:one_key/utils/log_util.dart';
import 'package:one_key/utils/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
class HomePage extends StatefulWidget{
... ... @@ -37,6 +38,15 @@ class HomePage extends StatefulWidget{
class HomePageState extends State<HomePage>{
// 信鸽推送
fake.Push _push = fake.Push();
StreamSubscription<String> _receiveDeviceToken;
StreamSubscription<fake.Message> _receiveMessage;
StreamSubscription<fake.Message> _receiveNotification;
StreamSubscription<String> _launchNotification;
StreamSubscription<String> _resumeNotification;
// 极光推送
final JPush jpush = new JPush();
List<Widget> pages = List<Widget>();
... ... @@ -64,6 +74,7 @@ class HomePageState extends State<HomePage>{
child: MyPage(),
));
initJPush();
// initXinge();
WidgetsBinding.instance.addPostFrameCallback((_){
if(widget.initialIndex==0)return;
getUntreatedMessage();
... ... @@ -111,6 +122,88 @@ class HomePageState extends State<HomePage>{
});
}
//初始化信鸽推送
void initXinge(){
_receiveDeviceToken =
_push.receiveDeviceToken().listen(_handleReceiveDeviceToken);
_receiveMessage = _push.receiveMessage().listen(_handleReceiveMessage);
_receiveNotification =
_push.receiveNotification().listen(_handleReceiveNotification);
_launchNotification =
_push.launchNotification().listen(_handleLaunchNotification);
_resumeNotification =
_push.resumeNotification().listen(_handleResumeNotification);
_push.startWork(enableDebug: !_isReleaseMode());
// 第二次打开应用再调用
SharedPreferences.getInstance().then((SharedPreferences sharedPref) {
if (sharedPref.getBool('firstStart') ?? true) {
sharedPref.setBool('firstStart', false);
} else {
_push.areNotificationsEnabled().then((bool isEnabled) {
if (!isEnabled) {
showCupertinoDialog(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: const Text('提示'),
content: const Text('开启通知权限可收到更多优质内容'),
actions: <Widget>[
CupertinoDialogAction(
child: const Text('取消'),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: const Text('设置'),
onPressed: () {
_push.openNotificationsSettings();
Navigator.of(context).pop();
},
),
],
);
},
);
}
});
}
});
}
bool _isReleaseMode() {
return const bool.fromEnvironment('dart.vm.product');
}
void _handleReceiveDeviceToken(String deviceToken) async {
String token=await _push.getDeviceToken();
print('receiveDeviceToken: $deviceToken - $token');
userTokenInit2(token);
}
void _handleReceiveMessage(fake.Message message) {
print(
'receiveMessage: ${message.title} - ${message.content} - ${message.customContent}');
}
void _handleReceiveNotification(fake.Message notification) {
print(
'receiveNotification: ${notification.title} - ${notification.content} - ${notification.customContent}');
}
void _handleLaunchNotification(String customContent) {
print('launchNotification: $customContent');
}
void _handleResumeNotification(String customContent) {
print('resumeNotification: $customContent');
}
//初始化推送token
userTokenInit(String registrationId){
UserModel userModel=Provider.of<UserModel>(context,listen: false);
... ... @@ -123,6 +216,18 @@ class HomePageState extends State<HomePage>{
userModel.userTokenInit(context, params);
}
//初始化推送token
userTokenInit2(String token){
UserModel userModel=Provider.of<UserModel>(context,listen: false);
userModel.token=token;
Map<String,String> params={
"sid":userModel.user.sellerid,
"account":userModel.user.account,
"user_token":token
};
userModel.userTokenInit(context, params);
}
//获取未处理在线预订消息
getUntreatedMessage(){
UserModel userModel=Provider.of<UserModel>(context,listen: false);
... ... @@ -221,6 +326,21 @@ class HomePageState extends State<HomePage>{
@override
void dispose() {
// TODO: implement dispose
if (_receiveDeviceToken != null) {
_receiveDeviceToken.cancel();
}
if (_receiveMessage != null) {
_receiveMessage.cancel();
}
if (_receiveNotification != null) {
_receiveNotification.cancel();
}
if (_launchNotification != null) {
_launchNotification.cancel();
}
if (_resumeNotification != null) {
_resumeNotification.cancel();
}
super.dispose();
LogUtil.v("home_dispose");
}
... ...
... ... @@ -16,6 +16,7 @@ import '../app.dart';
class UserModel with ChangeNotifier {
User _user;
String _registrationId;//极光推送registrationId
String _token;//信鸽推送token
User get user => _user;
... ... @@ -23,6 +24,13 @@ class UserModel with ChangeNotifier {
String get registrationId =>_registrationId;
String get token => _token;
set token(String value) {
_token = value;
}
/// 初始化 User
void initUser() {
if (App.sp.containsKey('user')) {
... ...
... ... @@ -218,6 +218,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.0"
fake_push:
dependency: "direct main"
description:
name: fake_push
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.4"
fixnum:
dependency: transitive
description:
... ... @@ -380,6 +387,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.3"
jaguar_serializer:
dependency: transitive
description:
name: jaguar_serializer
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.12"
jpush_flutter:
dependency: "direct main"
description:
... ...
... ... @@ -71,6 +71,8 @@ dependencies:
flutter_picker: ^1.1.3
# 网络状态
connectivity: ^0.4.8
# 信鸽推送
fake_push: ^0.5.4
dev_dependencies:
flutter_test:
... ...