From 3386f661894704b4b53f18d706a0fbc8e01e5d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BA=91=E9=A3=9E?= <78773304@qq.com> Date: Thu, 29 Oct 2020 17:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0getAlias=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jiguang/jpush/JPushPlugin.java | 9 ++++++ ios/Classes/JPushPlugin.m | 14 +++++++++ lib/jpush_flutter.dart | 29 +++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/jiguang/jpush/JPushPlugin.java b/android/src/main/java/com/jiguang/jpush/JPushPlugin.java index 2edaf719..2005e660 100644 --- a/android/src/main/java/com/jiguang/jpush/JPushPlugin.java +++ b/android/src/main/java/com/jiguang/jpush/JPushPlugin.java @@ -90,6 +90,8 @@ public void onMethodCall(MethodCall call, Result result) { getAllTags(call, result); } else if (call.method.equals("setAlias")) { setAlias(call, result); + } else if (call.method.equals("getAlias")) { + getAlias(call, result); } else if (call.method.equals("deleteAlias")) { deleteAlias(call, result);; } else if (call.method.equals("stopPush")) { @@ -236,6 +238,13 @@ public void setAlias(MethodCall call, Result result) { JPushInterface.setAlias(registrar.context(), sequence, alias); } + public void getAlias(MethodCall call, Result result) { + Log.d(TAG,"getAlias"); + sequence += 1; + callbackMap.put(sequence, result); + JPushInterface.getAlias(registrar.context(), sequence); + } + public void deleteAlias(MethodCall call, Result result) { Log.d(TAG,"deleteAlias:"); diff --git a/ios/Classes/JPushPlugin.m b/ios/Classes/JPushPlugin.m index 5d225312..88b1ae38 100644 --- a/ios/Classes/JPushPlugin.m +++ b/ios/Classes/JPushPlugin.m @@ -134,6 +134,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self getAllTags:call result:result]; } else if([@"setAlias" isEqualToString:call.method]) { [self setAlias:call result:result]; + } else if([@"getAlias" isEqualToString:call.method]) { + [self getAlias:call result:result]; } else if([@"deleteAlias" isEqualToString:call.method]) { [self deleteAlias:call result:result]; } else if([@"setBadge" isEqualToString:call.method]) { @@ -290,6 +292,18 @@ - (void)setAlias:(FlutterMethodCall*)call result:(FlutterResult)result { } seq: 0]; } +- (void)getAlias:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"getAlias"); + [JPUSHService getAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { + if (iResCode == 0) { + result(@{@"alias": iAlias ?: @""}); + } else { + NSError *error = [[NSError alloc] initWithDomain:@"JPush.Flutter" code:iResCode userInfo:nil]; + result([error flutterError]); + } + } seq: 0]; +} + - (void)deleteAlias:(FlutterMethodCall*)call result:(FlutterResult)result { JPLog(@"deleteAlias:%@",call.arguments); [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { diff --git a/lib/jpush_flutter.dart b/lib/jpush_flutter.dart index 8f343a72..b7e02115 100644 --- a/lib/jpush_flutter.dart +++ b/lib/jpush_flutter.dart @@ -70,7 +70,8 @@ class JPush { case "onReceiveMessage": return _onReceiveMessage(call.arguments.cast()); case "onReceiveNotificationAuthorization": - return _onReceiveNotificationAuthorization(call.arguments.cast()); + return _onReceiveNotificationAuthorization( + call.arguments.cast()); default: throw new UnsupportedError("Unrecognized Event"); } @@ -181,6 +182,23 @@ class JPush { return result; } + /// + /// 获取 alias. + /// + /// @param {String} alias + /// + /// @param {Function} success = ({"alias":String}) => { } + /// @param {Function} fail = ({"errorCode":int}) => { } + /// + Future> getAlias() async { + print(flutter_log + "getAlias:"); + + final Map result = + await _channel.invokeMethod('getAlias'); + + return result; + } + /// /// 删除原有 alias /// @@ -241,7 +259,7 @@ class JPush { /// void clearNotification({@required int notificationId}) { print(flutter_log + "clearNotification:"); - _channel.invokeListMethod("clearNotification",notificationId); + _channel.invokeListMethod("clearNotification", notificationId); } /// @@ -283,19 +301,18 @@ class JPush { return notification.toMap().toString(); } - /// 调用此 API 检测通知授权状态是否打开 Future isNotificationEnabled() async { - final Map result = await _channel.invokeMethod('isNotificationEnabled'); + final Map result = + await _channel.invokeMethod('isNotificationEnabled'); bool isEnabled = result["isEnabled"]; return isEnabled; } /// 调用此 API 跳转至系统设置中应用设置界面 - void openSettingsForNotification() { + void openSettingsForNotification() { _channel.invokeMethod('openSettingsForNotification'); } - } class NotificationSettingsIOS {