4

I'm using UILocalNotification in my project. My code:

        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate = event.date;
        notification.timeZone = [NSTimeZone systemTimeZone];        

        notification.hasAction = YES;
        notification.soundName = UILocalNotificationDefaultSoundName;
        [notification setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber+1];

        notification.alertBody = @"test alert body";

        notification.repeatInterval = NSDayCalendarUnit;

        NSLog(@"SCHEDULED NOTIFICATION  = %@", notification);

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

In time when notification should appear nothing is happen but application's badge icon value get +1. For iOS6 it's work fine. Where can be a problem?

UPDATE I do not get any alerts about notification while my app is run and when it's closed. Ony badge number is changing.

4

3 回答 3

0

另一个可能的问题是您已经拒绝了来自应用程序的推送通知。即使它说“允许推送通知”,弹出窗口实际上控制所有通知;推和本地。

请务必检查您的设置->通知中心->您的应用名称。我浪费了一个小时试图弄清楚出了什么问题,结果我只是禁用了推送-_-

于 2014-04-16T19:51:39.617 回答
0

找到了解决此问题的方法 ( https://devforums.apple.com/message/900205 )

只需延迟几毫秒即可安排通知。在我的情况下(消息应用程序)它工作得很好。

于 2013-10-02T07:25:13.290 回答
0

如果您经常在前台运行它,didReceiveLocalNotification则缺少:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary]   objectForKey:@"CFBundleName"]
                                                        message:notification.alertBody
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];

    [alertView show];

    // Reset badges if you want
    application.applicationIconBadgeNumber = 0;
}
于 2013-09-25T10:42:56.963 回答