UILocalnotification firing even after notification is cancelled

偶尔善良 提交于 2019-12-13 04:20:53

问题


The notification is firing even after it is cancelled. I tried checking cancelling method it turned out to be correct.

When I cancel a notification, the notification is again fired the next day

- (void)cancelNotification:(int)bookID
{
    NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
    NSLog(@"Cancelling... Before %d",[[[UIApplication sharedApplication]scheduledLocalNotifications]count]);

    for (UILocalNotification *notification in notifications)
    {

        int notifRemedyId = [[notification.userInfo objectForKey:@"kRemindMeNotificationRemedyIDKey"]intValue];

        NSLog(@"remedyID  : %d",remedyId);
        NSLog(@"notifyId : %d",notifRemedyId);
        if (remedyId == notifRemedyId)
        {
            [[UIApplication sharedApplication] cancelLocalNotification:notification];
        }

    }

}

I am thinking its because of repeatInterval.should repeatInterval property be removed.

SO I wanted to know where I am going wrong.


回答1:


1) First check retrieved particular notification object is not nil. Also check if that is the notification you want to cancel.

2) When you are sure notification object is not nil and the notification is the desired one, then fire below command. notification is your desired notification object.

[[UIApplication sharedApplication] cancelLocalNotification:notification];

3) I am looking at your code and I could see that you are not using bookID notification anywhere in your code. Not sure if you are using that code anymore.

4) No, you don't need to do anything extra to cancel repeating notification

Note: Please update your Question with final updated code. This looks confusing.



来源:https://stackoverflow.com/questions/16477894/uilocalnotification-firing-even-after-notification-is-cancelled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!