Cancel UILocalNotification

后端 未结 10 964
余生分开走
余生分开走 2020-11-27 12:53

I have a problem with my UILocalNotification.

I am scheduling the notification with my method.

- (void) sendNewNoteLocalReminder:(NSDate *)date  a         


        
10条回答
  •  孤街浪徒
    2020-11-27 13:33

    My solution is to remove all scheduled Notifications on these methods.

    -applicationDidFinishLaunchingWithOptions: 
    - (void)applicationDidBecomeActive:(UIApplication *)application;
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification;
    

    with

    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    You can still get to the LocalNotification object that activated your app by using.

        UILocalNotification *localNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey];
    

    Then I reschedule new Notifications on

    - (void)applicationDidEnterBackground:(UIApplication *)application;
    

    This avoids to have bookkeeping for all the notifications. I send some context information in the userInfo dictionary as well. This then helps to jump to the right place in the app.

提交回复
热议问题