美文网首页
iOS App系统消息数清除(IconBadgeNumber小红

iOS App系统消息数清除(IconBadgeNumber小红

作者: StevenHu_Sir | 来源:发表于2019-10-24 09:37 被阅读0次

    推送系统消息数清除(小红点)

    关键代码

    #include "AppDelegate.h"
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [GeneratedPluginRegistrant registerWithRegistry:self];
       return [super application:application didFinishLaunchingWithOptions:launchOptions];
    }
    
    -(void)applicationDidBecomeActive:(UIApplication *)application {
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
        [self resetBageNumber];
    }
    
    -(void)resetBageNumber
    {
        UILocalNotification *clearEpisodeNotification = [[UILocalNotification alloc] init];
        clearEpisodeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:(1*1)];
        clearEpisodeNotification.timeZone = [NSTimeZone defaultTimeZone];
        clearEpisodeNotification.applicationIconBadgeNumber = -1;
        [[UIApplication sharedApplication] scheduleLocalNotification:clearEpisodeNotification];
    }
    
    //点击App图标,使App从后台恢复至前台
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        [application setApplicationIconBadgeNumber:0];
        [application cancelAllLocalNotifications];
    }
    
    //按Home键使App进入后台
    - (void)applicationDidEnterBackground:(UIApplication *)application{
        [application setApplicationIconBadgeNumber:0];
        [application cancelAllLocalNotifications];
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS App系统消息数清除(IconBadgeNumber小红

          本文链接:https://www.haomeiwen.com/subject/rbcrvctx.html