|
|
@ -3,7 +3,6 @@ import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:platform/platform.dart';
|
|
|
|
import 'package:platform/platform.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
|
|
|
|
typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
|
|
|
|
|
|
|
|
|
|
|
|
class JPush {
|
|
|
|
class JPush {
|
|
|
@ -18,9 +17,8 @@ class JPush {
|
|
|
|
: _channel = channel,
|
|
|
|
: _channel = channel,
|
|
|
|
_platform = platform;
|
|
|
|
_platform = platform;
|
|
|
|
|
|
|
|
|
|
|
|
static final JPush _instance = new JPush.private(
|
|
|
|
static final JPush _instance =
|
|
|
|
const MethodChannel('jpush'),
|
|
|
|
new JPush.private(const MethodChannel('jpush'), const LocalPlatform());
|
|
|
|
const LocalPlatform());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventHandler _onReceiveNotification;
|
|
|
|
EventHandler _onReceiveNotification;
|
|
|
|
EventHandler _onOpenNotification;
|
|
|
|
EventHandler _onOpenNotification;
|
|
|
@ -34,8 +32,14 @@ class JPush {
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
print(flutter_log + "setup:");
|
|
|
|
print(flutter_log + "setup:");
|
|
|
|
|
|
|
|
|
|
|
|
_channel.invokeMethod('setup', { 'appKey': appKey, 'channel': channel, 'production': production, 'debug': debug});
|
|
|
|
_channel.invokeMethod('setup', {
|
|
|
|
|
|
|
|
'appKey': appKey,
|
|
|
|
|
|
|
|
'channel': channel,
|
|
|
|
|
|
|
|
'production': production,
|
|
|
|
|
|
|
|
'debug': debug
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// 初始化 JPush 必须先初始化才能执行其他操作(比如接收事件传递)
|
|
|
|
/// 初始化 JPush 必须先初始化才能执行其他操作(比如接收事件传递)
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -70,7 +74,8 @@ class JPush {
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// 申请推送权限,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。
|
|
|
|
/// 申请推送权限,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。
|
|
|
|
///
|
|
|
|
///
|
|
|
|
void applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
|
|
|
|
void applyPushAuthority(
|
|
|
|
|
|
|
|
[NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
|
|
|
|
print(flutter_log + "applyPushAuthority:");
|
|
|
|
print(flutter_log + "applyPushAuthority:");
|
|
|
|
|
|
|
|
|
|
|
|
if (!_platform.isIOS) {
|
|
|
|
if (!_platform.isIOS) {
|
|
|
@ -90,7 +95,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
|
|
|
|
Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
|
|
|
|
print(flutter_log + "setTags:");
|
|
|
|
print(flutter_log + "setTags:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags);
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('setTags', tags);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -103,7 +109,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> cleanTags() async {
|
|
|
|
Future<Map<dynamic, dynamic>> cleanTags() async {
|
|
|
|
print(flutter_log + "cleanTags:");
|
|
|
|
print(flutter_log + "cleanTags:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags');
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('cleanTags');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +125,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
|
|
|
|
Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
|
|
|
|
print(flutter_log + "addTags:");
|
|
|
|
print(flutter_log + "addTags:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags);
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('addTags', tags);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -132,7 +140,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
|
|
|
|
Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
|
|
|
|
print(flutter_log + "deleteTags:");
|
|
|
|
print(flutter_log + "deleteTags:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags);
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('deleteTags', tags);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -145,7 +154,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> getAllTags() async {
|
|
|
|
Future<Map<dynamic, dynamic>> getAllTags() async {
|
|
|
|
print(flutter_log + "getAllTags:");
|
|
|
|
print(flutter_log + "getAllTags:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags');
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('getAllTags');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -160,7 +170,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> setAlias(String alias) async {
|
|
|
|
Future<Map<dynamic, dynamic>> setAlias(String alias) async {
|
|
|
|
print(flutter_log + "setAlias:");
|
|
|
|
print(flutter_log + "setAlias:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias);
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('setAlias', alias);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -173,7 +184,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> deleteAlias() async {
|
|
|
|
Future<Map<dynamic, dynamic>> deleteAlias() async {
|
|
|
|
print(flutter_log + "deleteAlias:");
|
|
|
|
print(flutter_log + "deleteAlias:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias');
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('deleteAlias');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -187,7 +199,7 @@ class JPush {
|
|
|
|
Future setBadge(int badge) async {
|
|
|
|
Future setBadge(int badge) async {
|
|
|
|
print(flutter_log + "setBadge:");
|
|
|
|
print(flutter_log + "setBadge:");
|
|
|
|
|
|
|
|
|
|
|
|
await _channel.invokeMethod('setBadge', {"badge":badge});
|
|
|
|
await _channel.invokeMethod('setBadge', {"badge": badge});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -217,6 +229,15 @@ class JPush {
|
|
|
|
await _channel.invokeMethod('clearAllNotifications');
|
|
|
|
await _channel.invokeMethod('clearAllNotifications');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// 清空通知栏上某个通知
|
|
|
|
|
|
|
|
/// @param notificationId 通知 id,即:LocalNotification id
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
void clearNotification({@required int notificationId}) {
|
|
|
|
|
|
|
|
print(flutter_log + "clearNotification:");
|
|
|
|
|
|
|
|
_channel.invokeListMethod("clearNotification",notificationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// iOS Only
|
|
|
|
/// iOS Only
|
|
|
|
/// 点击推送启动应用的时候原生会将该 notification 缓存起来,该方法用于获取缓存 notification
|
|
|
|
/// 点击推送启动应用的时候原生会将该 notification 缓存起来,该方法用于获取缓存 notification
|
|
|
@ -227,7 +248,8 @@ class JPush {
|
|
|
|
Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
|
|
|
|
Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
|
|
|
|
print(flutter_log + "getLaunchAppNotification:");
|
|
|
|
print(flutter_log + "getLaunchAppNotification:");
|
|
|
|
|
|
|
|
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification');
|
|
|
|
final Map<dynamic, dynamic> result =
|
|
|
|
|
|
|
|
await _channel.invokeMethod('getLaunchAppNotification');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -255,6 +277,8 @@ class JPush {
|
|
|
|
return notification.toMap().toString();
|
|
|
|
return notification.toMap().toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationSettingsIOS {
|
|
|
|
class NotificationSettingsIOS {
|
|
|
@ -262,7 +286,7 @@ class NotificationSettingsIOS {
|
|
|
|
final bool alert;
|
|
|
|
final bool alert;
|
|
|
|
final bool badge;
|
|
|
|
final bool badge;
|
|
|
|
|
|
|
|
|
|
|
|
const NotificationSettingsIOS ({
|
|
|
|
const NotificationSettingsIOS({
|
|
|
|
this.sound = true,
|
|
|
|
this.sound = true,
|
|
|
|
this.alert = true,
|
|
|
|
this.alert = true,
|
|
|
|
this.badge = true,
|
|
|
|
this.badge = true,
|
|
|
@ -273,37 +297,31 @@ class NotificationSettingsIOS {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// @property {number} [buildId] - 通知样式:1 为基础样式,2 为自定义样式(需先调用 `setStyleCustom` 设置自定义样式)
|
|
|
|
|
|
|
|
/// @property {number} [id] - 通知 id, 可用于取消通知
|
|
|
|
|
|
|
|
/// @property {string} [title] - 通知标题
|
|
|
|
|
|
|
|
/// @property {string} [content] - 通知内容
|
|
|
|
|
|
|
|
/// @property {object} [extra] - extra 字段
|
|
|
|
/// @property {number} [buildId] - 通知样式:1 为基础样式,2 为自定义样式(需先调用 `setStyleCustom` 设置自定义样式)
|
|
|
|
/// @property {number} [fireTime] - 通知触发时间(毫秒)
|
|
|
|
/// @property {number} [id] - 通知 id, 可用于取消通知
|
|
|
|
/// // iOS Only
|
|
|
|
/// @property {string} [title] - 通知标题
|
|
|
|
/// @property {number} [badge] - 本地推送触发后应用角标值
|
|
|
|
/// @property {string} [content] - 通知内容
|
|
|
|
/// // iOS Only
|
|
|
|
/// @property {object} [extra] - extra 字段
|
|
|
|
/// @property {string} [soundName] - 指定推送的音频文件
|
|
|
|
/// @property {number} [fireTime] - 通知触发时间(毫秒)
|
|
|
|
/// // iOS 10+ Only
|
|
|
|
/// // iOS Only
|
|
|
|
/// @property {string} [subtitle] - 子标题
|
|
|
|
/// @property {number} [badge] - 本地推送触发后应用角标值
|
|
|
|
|
|
|
|
/// // iOS Only
|
|
|
|
|
|
|
|
/// @property {string} [soundName] - 指定推送的音频文件
|
|
|
|
|
|
|
|
/// // iOS 10+ Only
|
|
|
|
|
|
|
|
/// @property {string} [subtitle] - 子标题
|
|
|
|
|
|
|
|
class LocalNotification {
|
|
|
|
class LocalNotification {
|
|
|
|
|
|
|
|
final int buildId; //?
|
|
|
|
final int buildId;//?
|
|
|
|
|
|
|
|
final int id;
|
|
|
|
final int id;
|
|
|
|
final String title;
|
|
|
|
final String title;
|
|
|
|
final String content;
|
|
|
|
final String content;
|
|
|
|
final Map<String, String> extra;//?
|
|
|
|
final Map<String, String> extra; //?
|
|
|
|
final DateTime fireTime;
|
|
|
|
final DateTime fireTime;
|
|
|
|
final int badge;//?
|
|
|
|
final int badge; //?
|
|
|
|
final String soundName;//?
|
|
|
|
final String soundName; //?
|
|
|
|
final String subtitle;//?
|
|
|
|
final String subtitle; //?
|
|
|
|
|
|
|
|
|
|
|
|
const LocalNotification ({
|
|
|
|
const LocalNotification(
|
|
|
|
@required this.id,
|
|
|
|
{@required this.id,
|
|
|
|
@required this.title,
|
|
|
|
@required this.title,
|
|
|
|
@required this.content,
|
|
|
|
@required this.content,
|
|
|
|
@required this.fireTime,
|
|
|
|
@required this.fireTime,
|
|
|
@ -311,9 +329,8 @@ class LocalNotification {
|
|
|
|
this.extra,
|
|
|
|
this.extra,
|
|
|
|
this.badge = 0,
|
|
|
|
this.badge = 0,
|
|
|
|
this.soundName,
|
|
|
|
this.soundName,
|
|
|
|
this.subtitle
|
|
|
|
this.subtitle})
|
|
|
|
}):
|
|
|
|
: assert(id != null),
|
|
|
|
assert(id != null),
|
|
|
|
|
|
|
|
assert(title != null),
|
|
|
|
assert(title != null),
|
|
|
|
assert(content != null),
|
|
|
|
assert(content != null),
|
|
|
|
assert(fireTime != null);
|
|
|
|
assert(fireTime != null);
|
|
|
@ -329,7 +346,6 @@ class LocalNotification {
|
|
|
|
'badge': badge,
|
|
|
|
'badge': badge,
|
|
|
|
'soundName': soundName,
|
|
|
|
'soundName': soundName,
|
|
|
|
'subtitle': subtitle
|
|
|
|
'subtitle': subtitle
|
|
|
|
}..removeWhere((key, value)=>value==null);
|
|
|
|
}..removeWhere((key, value) => value == null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|