From 5f702412e3a7572c4f4f3c3134871c4d6638dec2 Mon Sep 17 00:00:00 2001 From: duhaiqiang Date: Thu, 9 Apr 2020 16:02:25 +0800 Subject: [PATCH] add resetBadge --- ios/Classes/JPushPlugin.m | 8 ++++++++ lib/jpush_flutter.dart | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/ios/Classes/JPushPlugin.m b/ios/Classes/JPushPlugin.m index 2e6c5041..3e45cb95 100644 --- a/ios/Classes/JPushPlugin.m +++ b/ios/Classes/JPushPlugin.m @@ -137,6 +137,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self deleteAlias:call result:result]; } else if([@"setBadge" isEqualToString:call.method]) { [self setBadge:call result:result]; + } else if([@"resetBadge" isEqualToString:call.method]) { + [self resetBadge:call result:result]; } else if([@"stopPush" isEqualToString:call.method]) { [self stopPush:call result:result]; } else if([@"resumePush" isEqualToString:call.method]) { @@ -311,6 +313,12 @@ - (void)setBadge:(FlutterMethodCall*)call result:(FlutterResult)result { [JPUSHService setBadge: badge]; } +- (void)resetBadge:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"resetBadge:"); + [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; + [JPUSHService resetBadge]; +} + - (void)stopPush:(FlutterMethodCall*)call result:(FlutterResult)result { JPLog(@"stopPush:"); [[UIApplication sharedApplication] unregisterForRemoteNotifications]; diff --git a/lib/jpush_flutter.dart b/lib/jpush_flutter.dart index 8f343a72..067a5065 100644 --- a/lib/jpush_flutter.dart +++ b/lib/jpush_flutter.dart @@ -208,6 +208,15 @@ class JPush { await _channel.invokeMethod('setBadge', {"badge": badge}); } + /// + /// 清空应用Badge(小红点) + /// + Future resetBadge() async { + print(flutter_log + "resetBadge:"); + + await _channel.invokeMethod('resetBadge'); + } + /// /// 停止接收推送,调用该方法后应用将不再受到推送,如果想要重新收到推送可以调用 resumePush。 ///