ios - 模拟器不显示 UILocalNotification

标签 ios timezone ios-simulator uilocalnotification uiapplication

我正在尝试合并在特定时间间隔后触发的本地通知,但是,在使用模拟器进行测试时,我似乎无法在任何时候显示通知。

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

//这是我的应用程序委托(delegate)中的 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/

相关文章:

iphone - 我的 Default.png 使用什么样的图像?我正在使用 iPhone 5's native resolution WITH the status bar, but it won' t 工作

.NET 时区信息

Java:这是在特定时区将当前时间作为日历对象获取的正确方法吗?

ios - 为 iOS 模拟器创建一个 dylib

ios - Poco 库 1.4.6 Xcode 5 为 iPhone 模拟器构建

xcode - 无法在 MAC 上使用 jenkins 在模拟器上运行测试用例

ios - Xcode 7 找不到名为的 Storyboard

ios - 警告 : Attempt to present whose view is not in the window hierarchy! swift

Java new Date() 当前时间错误

ios - 在应用程序进入后台之前允许用户输入