我正在尝试合并在一定时间间隔后触发的本地通知,但是,在用模拟器进行测试时,我似乎无法让通知在任何时候显示。
我只是想在创建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];
}
发布于 2015-10-20 18:48:12
1) 您注册使用通知了吗?,您可以在这里看到我在这里的帖子,因为我错过了这个简单的步骤。它在斯威夫特,但你得到了要点:UILocalNotification not doing anything
2) --我认为当您在应用程序中时,通知不起作用,因为这样它就违背了通知的目的。当您不在App,即后台模式或终止时,通知应该提醒您。所以当你在测试的时候,确保你不在这个应用程序中。
3)一般来说,根据我的经验,测试通知在真正的设备上比在模拟器上做得更好。
发布于 2015-10-20 18:15:41
iOS模拟器不能自动获得真实位置。
您可以设置一个假位置,以保持您的应用程序运行。尝试使用这个来检测它是否是一个模拟器,然后设置它。
#if (TARGET_IPHONE_SIMULATOR)
https://stackoverflow.com/questions/33247730
复制相似问题