Commit 555226514f21a623cd089c44bdaf7ddd9de01010

Authored by gaiyaguang
1 parent 67173141

2020/05/11 10:25

@@ -49,7 +49,7 @@ android { @@ -49,7 +49,7 @@ android {
49 49
50 ndk { 50 ndk {
51 //选择要添加的对应 cpu 类型的 .so 库。 51 //选择要添加的对应 cpu 类型的 .so 库。
52 - abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a' 52 + abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
53 } 53 }
54 54
55 manifestPlaceholders = [ 55 manifestPlaceholders = [
@@ -65,6 +65,16 @@ android { @@ -65,6 +65,16 @@ android {
65 // VIVO_APPKEY : "5811835841457", // VIVO平台注册的appkey 65 // VIVO_APPKEY : "5811835841457", // VIVO平台注册的appkey
66 // VIVO_APPID : "2882303761518358457", // VIVO平台注册的appid 66 // VIVO_APPID : "2882303761518358457", // VIVO平台注册的appid
67 ] 67 ]
  68 +
  69 +// manifestPlaceholders = [
  70 +// XG_ACCESS_ID : '2100332241',
  71 +// XG_ACCESS_KEY : 'A51T8RX1HS1W',
  72 +// XG_ACCESS_SCHEME: 'fake_push',// 非官方参数,可自定义,统一打开方式为 intent
  73 +// HW_APPID : '100728875',
  74 +// XIAOMI_APPID : '2882303761517989384',
  75 +// XIAOMI_APPKEY : '5141798993384',
  76 +// PACKAGE_NAME : "${applicationId}",// 小米通道
  77 +// ]
68 } 78 }
69 79
70 signingConfigs { 80 signingConfigs {
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;
  5 +import 'package:flutter/cupertino.dart';
4 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
5 import 'package:flutter_screenutil/flutter_screenutil.dart'; 7 import 'package:flutter_screenutil/flutter_screenutil.dart';
6 import 'package:jpush_flutter/jpush_flutter.dart'; 8 import 'package:jpush_flutter/jpush_flutter.dart';
7 -import 'package:one_key/app.dart';  
8 import 'package:one_key/models/message.dart'; 9 import 'package:one_key/models/message.dart';
9 import 'package:one_key/pages/message/message_page.dart'; 10 import 'package:one_key/pages/message/message_page.dart';
10 import 'package:one_key/pages/my/my_page.dart'; 11 import 'package:one_key/pages/my/my_page.dart';
@@ -15,12 +16,12 @@ import 'package:one_key/provider/my_model.dart'; @@ -15,12 +16,12 @@ import 'package:one_key/provider/my_model.dart';
15 import 'package:one_key/provider/notebook_model.dart'; 16 import 'package:one_key/provider/notebook_model.dart';
16 import 'package:one_key/provider/user_model.dart'; 17 import 'package:one_key/provider/user_model.dart';
17 import 'package:one_key/res/colors.dart'; 18 import 'package:one_key/res/colors.dart';
18 -import 'package:one_key/route/navigate_service.dart';  
19 import 'package:one_key/utils/log_util.dart'; 19 import 'package:one_key/utils/log_util.dart';
20 import 'package:one_key/utils/navigator_util.dart'; 20 import 'package:one_key/utils/navigator_util.dart';
21 import 'package:one_key/utils/utils.dart'; 21 import 'package:one_key/utils/utils.dart';
22 import 'package:provider/provider.dart'; 22 import 'package:provider/provider.dart';
23 import 'package:flutter/services.dart'; 23 import 'package:flutter/services.dart';
  24 +import 'package:shared_preferences/shared_preferences.dart';
24 25
25 class HomePage extends StatefulWidget{ 26 class HomePage extends StatefulWidget{
26 27
@@ -37,6 +38,15 @@ class HomePage extends StatefulWidget{ @@ -37,6 +38,15 @@ class HomePage extends StatefulWidget{
37 38
38 class HomePageState extends State<HomePage>{ 39 class HomePageState extends State<HomePage>{
39 40
  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;
  48 +
  49 +// 极光推送
40 final JPush jpush = new JPush(); 50 final JPush jpush = new JPush();
41 51
42 List<Widget> pages = List<Widget>(); 52 List<Widget> pages = List<Widget>();
@@ -64,6 +74,7 @@ class HomePageState extends State<HomePage>{ @@ -64,6 +74,7 @@ class HomePageState extends State<HomePage>{
64 child: MyPage(), 74 child: MyPage(),
65 )); 75 ));
66 initJPush(); 76 initJPush();
  77 +// initXinge();
67 WidgetsBinding.instance.addPostFrameCallback((_){ 78 WidgetsBinding.instance.addPostFrameCallback((_){
68 if(widget.initialIndex==0)return; 79 if(widget.initialIndex==0)return;
69 getUntreatedMessage(); 80 getUntreatedMessage();
@@ -111,6 +122,88 @@ class HomePageState extends State<HomePage>{ @@ -111,6 +122,88 @@ class HomePageState extends State<HomePage>{
111 }); 122 });
112 } 123 }
113 124
  125 + //初始化信鸽推送
  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 + });
  174 + }
  175 +
  176 + bool _isReleaseMode() {
  177 + return const bool.fromEnvironment('dart.vm.product');
  178 + }
  179 +
  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}');
  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 +
114 //初始化推送token 207 //初始化推送token
115 userTokenInit(String registrationId){ 208 userTokenInit(String registrationId){
116 UserModel userModel=Provider.of<UserModel>(context,listen: false); 209 UserModel userModel=Provider.of<UserModel>(context,listen: false);
@@ -123,6 +216,18 @@ class HomePageState extends State<HomePage>{ @@ -123,6 +216,18 @@ class HomePageState extends State<HomePage>{
123 userModel.userTokenInit(context, params); 216 userModel.userTokenInit(context, params);
124 } 217 }
125 218
  219 + //初始化推送token
  220 + userTokenInit2(String token){
  221 + UserModel userModel=Provider.of<UserModel>(context,listen: false);
  222 + userModel.token=token;
  223 + Map<String,String> params={
  224 + "sid":userModel.user.sellerid,
  225 + "account":userModel.user.account,
  226 + "user_token":token
  227 + };
  228 + userModel.userTokenInit(context, params);
  229 + }
  230 +
126 //获取未处理在线预订消息 231 //获取未处理在线预订消息
127 getUntreatedMessage(){ 232 getUntreatedMessage(){
128 UserModel userModel=Provider.of<UserModel>(context,listen: false); 233 UserModel userModel=Provider.of<UserModel>(context,listen: false);
@@ -221,6 +326,21 @@ class HomePageState extends State<HomePage>{ @@ -221,6 +326,21 @@ class HomePageState extends State<HomePage>{
221 @override 326 @override
222 void dispose() { 327 void dispose() {
223 // 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 + }
224 super.dispose(); 344 super.dispose();
225 LogUtil.v("home_dispose"); 345 LogUtil.v("home_dispose");
226 } 346 }
@@ -16,6 +16,7 @@ import '../app.dart'; @@ -16,6 +16,7 @@ import '../app.dart';
16 class UserModel with ChangeNotifier { 16 class UserModel with ChangeNotifier {
17 User _user; 17 User _user;
18 String _registrationId;//极光推送registrationId 18 String _registrationId;//极光推送registrationId
  19 + String _token;//信鸽推送token
19 20
20 User get user => _user; 21 User get user => _user;
21 22
@@ -23,6 +24,13 @@ class UserModel with ChangeNotifier { @@ -23,6 +24,13 @@ class UserModel with ChangeNotifier {
23 24
24 String get registrationId =>_registrationId; 25 String get registrationId =>_registrationId;
25 26
  27 +
  28 + String get token => _token;
  29 +
  30 + set token(String value) {
  31 + _token = value;
  32 + }
  33 +
26 /// 初始化 User 34 /// 初始化 User
27 void initUser() { 35 void initUser() {
28 if (App.sp.containsKey('user')) { 36 if (App.sp.containsKey('user')) {
@@ -218,6 +218,13 @@ packages: @@ -218,6 +218,13 @@ packages:
218 url: "https://pub.flutter-io.cn" 218 url: "https://pub.flutter-io.cn"
219 source: hosted 219 source: hosted
220 version: "0.2.0" 220 version: "0.2.0"
  221 + fake_push:
  222 + dependency: "direct main"
  223 + description:
  224 + name: fake_push
  225 + url: "https://pub.flutter-io.cn"
  226 + source: hosted
  227 + version: "0.5.4"
221 fixnum: 228 fixnum:
222 dependency: transitive 229 dependency: transitive
223 description: 230 description:
@@ -380,6 +387,13 @@ packages: @@ -380,6 +387,13 @@ packages:
380 url: "https://pub.flutter-io.cn" 387 url: "https://pub.flutter-io.cn"
381 source: hosted 388 source: hosted
382 version: "0.3.3" 389 version: "0.3.3"
  390 + jaguar_serializer:
  391 + dependency: transitive
  392 + description:
  393 + name: jaguar_serializer
  394 + url: "https://pub.flutter-io.cn"
  395 + source: hosted
  396 + version: "2.2.12"
383 jpush_flutter: 397 jpush_flutter:
384 dependency: "direct main" 398 dependency: "direct main"
385 description: 399 description:
@@ -71,6 +71,8 @@ dependencies: @@ -71,6 +71,8 @@ dependencies:
71 flutter_picker: ^1.1.3 71 flutter_picker: ^1.1.3
72 # 网络状态 72 # 网络状态
73 connectivity: ^0.4.8 73 connectivity: ^0.4.8
  74 +# 信鸽推送
  75 + fake_push: ^0.5.4
74 76
75 dev_dependencies: 77 dev_dependencies:
76 flutter_test: 78 flutter_test: