我在我的项目中使用 UILocalNotification。我的代码:
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];
在应该出现通知的时候,什么也没有发生,但应用程序的徽章图标值得到 +1。对于 iOS6,它工作正常。哪里会出问题?
更新 在我的应用程序运行和关闭时,我没有收到任何关于通知的警报。唯一的徽章号码正在改变。
最佳答案
如果您在前台运行它,通常会丢失 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;
}
关于iphone - UILocalNotification 没有出现在 iOS7 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19002506/