0

我想要合并在一定时间间隔后触发的localnotifications,但是,我似乎无法在使用模拟器进行测试时在任何时候显示通知。模拟器不显示UILocalNotification

我只是想在创建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]; 

//这是在我的应用程序委托

UIApplicationState state = [application applicationState]; 
if (state == UIApplicationStateActive) { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder" message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
} 
+0

如果您注释掉时区,会发生什么情况? – rocky

回答

5

1)有您注册为使用通知?你可以在这里看到我的帖子,关于我所面对的只是错过了这个简单的步骤。这是斯威夫特,但你得到的要点:UILocalNotification not doing anything

2)我不觉得当你在App的内部通知的工作,因为那违背了通知的目的。当您不在应用程序中时,通知应该提醒您,如背景模式或终止。所以当你测试时,确保你没有在应用程序中

3)一般来说,测试通知最好在真实设备上从我的经验比模拟器完成。

+0

非常感谢你!我需要更多地阅读文档,而不是依靠教程:)我很惊讶,我找不到任何有关注册本地通知的信息! – HJordan35

+0

是的,没有一个教程提到过这个,我不明白为什么。但正如你所说,这也有助于我更详细地阅读文档。 Thx接受答案。 – Lavvo

0

的iOS模拟器不能自动得到真正的位置didReceiveLocalNotification。

您可以设置一个虚拟的位置来让您的应用继续运行。尝试使用它来检测它是否是模拟器,然后设置它。

#if (TARGET_IPHONE_SIMULATOR)