【问题标题】:Simulator not displaying UILocalNotification模拟器不显示 UILocalNotification
【发布时间】:2016-01-19 18:23:51
【问题描述】:

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

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

【问题讨论】:

  • 如果注释掉 timeZone 行会怎样?

标签: ios timezone ios-simulator uilocalnotification uiapplication


【解决方案1】:

1) 您注册好使用通知了吗?您可以在此处查看我的帖子,了解我只是错过了这个简单的步骤。它在 Swift 中,但你明白了要点:UILocalNotification not doing anything

2) 我认为当您在应用程序内部时通知不起作用,因为这样就违背了通知的目的。当您不在应用程序中时,通知应该提醒您,即后台模式或终止。所以当你在测试时,请确保你不在应用中

3) 一般来说,根据我的经验,在真机上测试通知效果比在模拟器上更好

【讨论】:

  • 非常感谢您!我需要开始更多地阅读文档而不是依赖教程 :) 我很惊讶我找不到任何关于注册本地通知的信息!
  • 是的,没有一个教程提到过这个,我不明白为什么。但就像你说的那样,它也帮助我更详细地阅读了文档。感谢您接受答案。
【解决方案2】:

iOS 模拟器无法自动获取真实位置。

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

#if (TARGET_IPHONE_SIMULATOR)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 2013-09-30
    • 2021-03-08
    • 2014-12-28
    • 2011-08-14
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多