【问题标题】:iOS >> UILocalNotification Got LostiOS >> UILocalNotification 丢失了
【发布时间】:2014-09-22 09:45:41
【问题描述】:

在我的应用程序中,可能会出现多个本地通知将在“触发日期”非常接近的情况下非常接近地触发的情况。

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

但是...如果应用程序处于后台或关闭状态,并且我单击主屏幕中弹出的“弹出窗口”,此方法仅捕获第一个通知,而其他通知似乎丢失了;我需要它们……

有人吗?

【问题讨论】:

  • 不能使用NSNotification的userInfo吗?

标签: ios objective-c uilocalnotification appdelegate


【解决方案1】:

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

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
}

【讨论】:

    猜你喜欢
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 2018-07-27
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    相关资源
    最近更新 更多