iOS>> UILocalNotification失去了

时间:2014-09-22 09:45:41

标签: ios objective-c uilocalnotification appdelegate

在我的应用程序中,可能会出现一个场景,其中几个本地通知将以非常接近的开火日期非常紧密地发布。

如果应用程序在前台,AppDelegate似乎通过didReceiveLocalNotification方法捕获它们。

但是......如果应用程序在后台或关闭,我点击“弹出式按钮”。在主屏幕中弹出,此方法仅捕获第一个通知,而其他通知似乎丢失;我需要他们所有人......

任何?

1 个答案:

答案 0 :(得分:0)

您是否在下方尝试过本地通知?

NSArray *pendingNotifications = [[[UIApplication sharedApplication] scheduledLocalNotifications] sortedArrayUsingComparator:^(id obj1, id obj2) {
        if ([obj1 isKindOfClass:[UILocalNotification class]] && [obj2 isKindOfClass:[UILocalNotification class]])
        {
            UILocalNotification *notif1 = (UILocalNotification *)obj1;
            UILocalNotification *notif2 = (UILocalNotification *)obj2;
            return [notif1.fireDate compare:notif2.fireDate];
        }

        return NSOrderedSame;
    }];
// if there are any pending notifications -> adjust their badge number
if (pendingNotifications.count != 0)
{
    //do something
}