Iphone模拟器:本地通知触发两次但从未显示?
模拟器和本地通知是否存在错误,或者我做错了什么。
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在应用程序运行时收到本地/推送通知,您将不会看到任何警报。除非您在应用程序中显示自己的警报: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.