1

我一直在查看 UILocalNotification 的 API。我想在被击中时只设置徽章编号。没有弹出窗口。我尝试将通知设置为仅具有 1 的徽章编号且没有警报正文。但这没有用。

//Add new local push notification
locationNotification.fireDate = date;
locationNotification.timeZone = [NSTimeZone defaultTimeZone];
//locationNotification.alertBody = [NSString stringWithFormat:body];
//locationNotification.alertAction = @"Ok";
//locationNotification.soundName = UILocalNotificationDefaultSoundName;
locationNotification.applicationIconBadgeNumber = 1;

这可能吗?我只想在他们打开应用程序后显示消息。

4

2 回答 2

1

我为我从事的一个项目完成了类似的事情。我只需要显示一个徽章编号,没有警报。您可能需要在通知中添加“声音”,我所做的是添加0.5第二个静音文件。我的代码看起来像这样。

        UILocalNotification *notif = [[UILocalNotification alloc] init];
        notif.fireDate = [NSDate  date];
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.soundName = @"silence.caf";
        notif.applicationIconBadgeNumber = 2;
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];

希望这可以帮助!

于 2012-06-15T14:12:21.737 回答
0

这是一个老问题,但希望这会对某人有所帮助。我认为根本不可能安排静默本地通知,但似乎确实如此。

这有效:

    UILocalNotification* notification = [[UILocalNotification alloc] init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
    notification.timeZone = [NSTimeZone systemTimeZone];
    notification.alertBody = nil;        
    notification.applicationIconBadgeNumber = 99;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

我还尝试向 userInfo 属性添加一些信息,以便我可以在计划的通知中识别此通知,但这似乎阻止了通知被触发。

取而代之的是,我现在使用无声音频文件作为 soundName 属性,以便我可以对此进行测试。然而,静音音频文件似乎并不需要实际触发通知。

如果您想做的事情比将徽章更新为您在计划时知道的值更有用,那么您需要使用静默推送通知并设置“内容可用”标志。

于 2016-08-29T05:55:42.577 回答