通知已启动后的iOS本地通知列表

时间:2013-02-11 22:04:28

标签: ios notifications

我的应用程序在后台运行并监视蓝牙数据。当数据进入时,我会显示用户需要打开应用程序的通知,以便我可以处理刚进入的数据。

我正在写iOS 5及更高版本。

我使用此代码发出通知:

        UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
        if (alarm) {

            alarm.fireDate = [NSDate date];
            alarm.timeZone = [NSTimeZone defaultTimeZone];
            alarm.repeatInterval = 0;
            alarm.soundName = @"alarmsound.caf";
            alarm.alertBody = message;

            [app scheduleLocalNotification:alarm];
        }

我希望您能从该代码中看到通知立即触发。

我遇到的问题是我似乎无法检测通知栏上是否已有通知。我尝试过使用:

        NSArray *oldNotifications = [app scheduledLocalNotifications];

        // Clear out the old notification before scheduling a new one.
        if ([oldNotifications count] > 0)
            [app cancelAllLocalNotifications];

但这似乎不起作用,因为oldNotifications计数始终为0,即使通知栏上有大量的通知。我认为这是因为通知已经被解雇了?

基本上我只想通知用户一次,除非他们在不打开应用程序的情况下解雇该通知。如果我还可以增加应用程序徽章值以便用户知道有多少蓝牙消息进入,那将是很好的。相反,我只是为每个传入的消息获得一个全新的通知。

我如何只通知用户一次,如果他们已经驳回通知,则只会再次通知他们?

0 个答案:

没有答案