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