| | |
| | | import 'dart:convert'; |
| | | import 'dart:io'; |
| | | import 'dart:ui'; |
| | | |
| | |
| | | import 'package:flutter_baidu_mapapi_base/src/map/bmf_types.dart'; |
| | | import 'package:flutter/services.dart'; |
| | | import 'package:jpush_flutter/jpush_flutter.dart'; |
| | | import 'package:locations/api/http.dart'; |
| | | import 'package:locations/model/user/user_info.dart'; |
| | | import 'package:locations/ui/main/location.dart'; |
| | | import 'package:locations/ui/sos/sos.dart'; |
| | | import 'package:locations/utils/pageutils.dart'; |
| | | import 'package:locations/utils/user_util.dart'; |
| | | |
| | | class PushUtil { |
| | | static JPush _jpush = JPush(); |
| | | import 'global.dart'; |
| | | |
| | | static init() async { |
| | | class PushUtil { |
| | | static final JPush _jpush = JPush(); |
| | | |
| | | static init(BuildContext context) async { |
| | | try { |
| | | _jpush.addEventHandler( |
| | | onReceiveNotification: (Map<String, dynamic> message) async { |
| | | print("flutter onReceiveNotification: $message"); |
| | | }, onOpenNotification: (Map<String, dynamic> message) async { |
| | | print("flutter onOpenNotification: $message"); |
| | | var extra = message["extras"]["cn.jpush.android.EXTRA"]; |
| | | extra = jsonDecode(extra); |
| | | //打开页面 |
| | | var type = extra["type"]; |
| | | |
| | | if (type == "sos") { |
| | | //SOS |
| | | NavigatorUtil.navigateToNextPagePush(SOSPage(title: "")); |
| | | } else if (type == "requestLocation") { |
| | | //请求定位 |
| | | LocationPage.getLocationInvite(navigatorKey.currentState!.context); |
| | | } |
| | | }, onReceiveMessage: (Map<String, dynamic> message) async { |
| | | print("flutter onReceiveMessage: ${message["message"]}"); |
| | | }, onReceiveNotificationAuthorization: |
| | |
| | | // Platform messages may fail, so we use a try/catch PlatformException. |
| | | _jpush.getRegistrationID().then((rid) { |
| | | print("flutter get registration id : $rid"); |
| | | UserApiUtil.uploadPushRegId(context, rid); |
| | | }); |
| | | |
| | | //如果登录了就设置用户的uid |