|
|
@ -1,7 +1,7 @@
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'dart:io' show Platform, stdout;
|
|
|
|
import 'dart:io' show Platform;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
|
|
|
|
typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
|
|
|
@ -19,16 +19,6 @@ class JPush {
|
|
|
|
static EventHandler _onOpenNotification;
|
|
|
|
static EventHandler _onOpenNotification;
|
|
|
|
static EventHandler _onReceiveMessage;
|
|
|
|
static EventHandler _onReceiveMessage;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <String, dynamic>{
|
|
|
|
|
|
|
|
// 'source': source.index,
|
|
|
|
|
|
|
|
// 'maxWidth': maxWidth,
|
|
|
|
|
|
|
|
// 'maxHeight': maxHeight,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void setup({
|
|
|
|
static void setup({
|
|
|
|
String appKey,
|
|
|
|
String appKey,
|
|
|
|
String channel,
|
|
|
|
String channel,
|
|
|
@ -36,9 +26,9 @@ class JPush {
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
_channel.invokeMethod('setup', { 'appKey': appKey, 'channel': channel, 'production': production });
|
|
|
|
_channel.invokeMethod('setup', { 'appKey': appKey, 'channel': channel, 'production': production });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 初始化 JPush 必须先初始化才能执行其他操作(比如接收事件传递)
|
|
|
|
/// 初始化 JPush 必须先初始化才能执行其他操作(比如接收事件传递)
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static void addEventHandler({
|
|
|
|
static void addEventHandler({
|
|
|
|
EventHandler onReceiveNotification,
|
|
|
|
EventHandler onReceiveNotification,
|
|
|
|
EventHandler onOpenNotification,
|
|
|
|
EventHandler onOpenNotification,
|
|
|
@ -63,13 +53,11 @@ class JPush {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 申请推送权限当,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。
|
|
|
|
/// 申请推送权限当,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
|
|
|
|
static Future applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
|
|
|
|
// TODO: 样式
|
|
|
|
|
|
|
|
// await _channel.invokeMethod('applyPushAuthority');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Platform.isIOS) {
|
|
|
|
if (!Platform.isIOS) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -77,137 +65,137 @@ class JPush {
|
|
|
|
_channel.invokeMethod('applyPushAuthority', iosSettings.toMap());
|
|
|
|
_channel.invokeMethod('applyPushAuthority', iosSettings.toMap());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 设置 Tag (会覆盖之前设置的 tags)
|
|
|
|
/// 设置 Tag (会覆盖之前设置的 tags)
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Array} params = [String]
|
|
|
|
/// @param {Array} params = [String]
|
|
|
|
* @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
/// @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
|
|
|
|
static Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags);
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 清空所有 tags。
|
|
|
|
/// 清空所有 tags。
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
/// @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> cleanTags() async {
|
|
|
|
static Future<Map<dynamic, dynamic>> cleanTags() async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags');
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 在原有 tags 的基础上添加 tags
|
|
|
|
/// 在原有 tags 的基础上添加 tags
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Array} tags = [String]
|
|
|
|
/// @param {Array} tags = [String]
|
|
|
|
* @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
/// @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
|
|
static Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
|
|
|
|
static Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags);
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 删除指定的 tags
|
|
|
|
/// 删除指定的 tags
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Array} tags = [String]
|
|
|
|
/// @param {Array} tags = [String]
|
|
|
|
* @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
/// @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
|
|
|
|
static Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags);
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 获取所有当前绑定的 tags
|
|
|
|
/// 获取所有当前绑定的 tags
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
/// @param {Function} success = ({"tags":[String]}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> getAllTags() async {
|
|
|
|
static Future<Map<dynamic, dynamic>> getAllTags() async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags');
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 重置 alias.
|
|
|
|
/// 重置 alias.
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {String} alias
|
|
|
|
/// @param {String} alias
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Function} success = ({"alias":String}) => { }
|
|
|
|
/// @param {Function} success = ({"alias":String}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> setAlias(String alias) async {
|
|
|
|
static Future<Map<dynamic, dynamic>> setAlias(String alias) async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias);
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 删除原有 alias
|
|
|
|
/// 删除原有 alias
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Function} success = ({"alias":String}) => { }
|
|
|
|
/// @param {Function} success = ({"alias":String}) => { }
|
|
|
|
* @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
/// @param {Function} fail = ({"errorCode":int}) => { }
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> deleteAlias() async {
|
|
|
|
static Future<Map<dynamic, dynamic>> deleteAlias() async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias');
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* iOS Only
|
|
|
|
/// iOS Only
|
|
|
|
* 设置应用 Badge(小红点)
|
|
|
|
/// 设置应用 Badge(小红点)
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* @param {Int} badge
|
|
|
|
/// @param {Int} badge
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future setBadge(int badge) async {
|
|
|
|
static Future setBadge(int badge) async {
|
|
|
|
await _channel.invokeMethod('setBadge', badge);
|
|
|
|
await _channel.invokeMethod('setBadge', badge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 停止接收推送,调用该方法后应用将不再受到推送,如果想要重新收到推送可以调用 resumePush。
|
|
|
|
/// 停止接收推送,调用该方法后应用将不再受到推送,如果想要重新收到推送可以调用 resumePush。
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future stopPush() async {
|
|
|
|
static Future stopPush() async {
|
|
|
|
await _channel.invokeMethod('stopPush');
|
|
|
|
await _channel.invokeMethod('stopPush');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 恢复推送功能。
|
|
|
|
/// 恢复推送功能。
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future resumePush() async {
|
|
|
|
static Future resumePush() async {
|
|
|
|
await _channel.invokeMethod('resumePush');
|
|
|
|
await _channel.invokeMethod('resumePush');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 清空通知栏上的所有通知。
|
|
|
|
/// 清空通知栏上的所有通知。
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future clearAllNotifications() async {
|
|
|
|
static Future clearAllNotifications() async {
|
|
|
|
await _channel.invokeMethod('clearAllNotifications');
|
|
|
|
await _channel.invokeMethod('clearAllNotifications');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* iOS Only
|
|
|
|
/// iOS Only
|
|
|
|
* 点击推送启动应用的时候原生会将该 notification 缓存起来,该方法用于获取缓存 notification
|
|
|
|
/// 点击推送启动应用的时候原生会将该 notification 缓存起来,该方法用于获取缓存 notification
|
|
|
|
* 注意:notification 可能是 remoteNotification 和 localNotification,两种推送字段不一样。
|
|
|
|
/// 注意:notification 可能是 remoteNotification 和 localNotification,两种推送字段不一样。
|
|
|
|
* 如果不是通过点击推送启动应用,比如点击应用 icon 直接启动应用,notification 会返回 @{}。
|
|
|
|
/// 如果不是通过点击推送启动应用,比如点击应用 icon 直接启动应用,notification 会返回 @{}。
|
|
|
|
* @param {Function} callback = (Object) => {}
|
|
|
|
/// @param {Function} callback = (Object) => {}
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
|
|
|
|
static Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification');
|
|
|
|
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification');
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
///
|
|
|
|
* 获取 RegistrationId, JPush 可以通过制定 RegistrationId 来进行推送。
|
|
|
|
/// 获取 RegistrationId, JPush 可以通过制定 RegistrationId 来进行推送。
|
|
|
|
*
|
|
|
|
///
|
|
|
|
* * @param {Function} callback = (String) => {}
|
|
|
|
/// @param {Function} callback = (String) => {}
|
|
|
|
*/
|
|
|
|
///
|
|
|
|
static Future<String> getRegistrationID() async {
|
|
|
|
static Future<String> getRegistrationID() async {
|
|
|
|
final String rid = await _channel.invokeMethod('getRegistrationID');
|
|
|
|
final String rid = await _channel.invokeMethod('getRegistrationID');
|
|
|
|
return rid;
|
|
|
|
return rid;
|
|
|
|