我正在尝试合并在特定时间间隔后触发的本地通知,但是,在使用模拟器进行测试时,似乎无法在任何时候显示该通知。
我只是想在创建后的10秒内显示本地通知,但是,无论在前台还是在后台运行该应用程序时,都不会显示任何内容。
我想念什么吗?可能与时区有关吗?
//通知设置
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNotification.alertBody = @"Testing";
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
//这是我的应用程序委托中的didReceiveLocalNotification
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder" message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
最佳答案
1)您是否已注册要使用的通知? 您可以在这里看到我的帖子,这只是我错过了这一简单步骤而遇到的问题。它在Swift中,但要领:UILocalNotification not doing anything
2)我认为当您位于应用程序中时,通知不起作用,因为那样做就无法达到通知的目的。当您不在应用程序(即后台模式或已终止)中时,通知会提醒您。因此,在进行测试时,请确保您不在应用程序中
3)一般来说,根据我的经验,在真实设备上,测试通知比模拟器更好。
关于ios - 模拟器未显示UILocalNotification,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33247730/