Removing UILocalNotification from notification tray programmatically

后端 未结 7 1804
再見小時候
再見小時候 2020-12-29 10:29

Is there a way to programmatically remove/dismiss UILocalNotification from Notification Tray. I am able to cancel the notification which removes the notificatio

7条回答
  •  心在旅途
    2020-12-29 10:48

    I was fiddling with some code and I was wondering why local notifications are stored in the notification center if the application is in the foreground. It's probably because Apple doesn't know what you are doing with them and honestly doesn't care; so they do their job.

    As far as the question is concerned, I do the following:

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
        if (application.applicationState == UIApplicationStateActive)
        {
            NSLog(@"active");
    
            // display some foreground notification;
            [application cancelLocalNotification:notification];
        }
        else
        {
            NSLog(@"inactive");
        }
    }
    

提交回复
热议问题