Iphone模拟器:本地通知触发两次但从未显示?

发布于 2024-09-16 09:22:48 字数 1561 浏览 4 评论 0原文

模拟器和本地通知是否存在错误,或者我做错了什么。

// on button click fire off notification for 30 seconds from now
-(IBAction)scheduleNotification{
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    NSDate *item = [NSDate dateWithTimeIntervalSinceNow:30]; 

    if (localNotif == nil)
        return;     
    localNotif.fireDate = item;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertBody =  NSLocalizedString(@"Test Notification", nil);
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 0;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
}   



- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Recieved Notification %@",notif);
}

didReceiveLocalNotification 记录了 2 个通知,但模拟器从未真正显示通知。

Recieved Notification <UIConcreteLocalNotification: 0x5943450>{fire date = 2010-08-25 09:36:25 -0400, time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0, next fire date = 2010-08-25 09:36:25 -0400}

Recieved Notification <UIConcreteLocalNotification: 0x5c53e00>{fire date = 2010-08-25 09:36:25 -0400, time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0, next fire date = (null)}

Is there a bug with the simulator and Local Notifications or am I doing something incorrectly.

// on button click fire off notification for 30 seconds from now
-(IBAction)scheduleNotification{
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    NSDate *item = [NSDate dateWithTimeIntervalSinceNow:30]; 

    if (localNotif == nil)
        return;     
    localNotif.fireDate = item;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertBody =  NSLocalizedString(@"Test Notification", nil);
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 0;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
}   



- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Recieved Notification %@",notif);
}

didReceiveLocalNotification logs 2 notifications, but the simulator never actually displays a notification.

Recieved Notification <UIConcreteLocalNotification: 0x5943450>{fire date = 2010-08-25 09:36:25 -0400, time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0, next fire date = 2010-08-25 09:36:25 -0400}

Recieved Notification <UIConcreteLocalNotification: 0x5c53e00>{fire date = 2010-08-25 09:36:25 -0400, time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0, next fire date = (null)}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-09-23 09:22:48

如果您在应用程序运行时收到本地/推送通知,您将不会看到任何警报。除非您在应用程序中显示自己的警报:didReceiveLocalNotification:,当然。

You won't see any alert if you receive local/push notification while your app is running. Unless you show your own alert in application: didReceiveLocalNotification:, certainly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文