gpt4 book ai didi

ios - 模拟器不显示 UILocalNotification

转载 作者:行者123 更新时间:2023-12-01 17:29:42 28 4
gpt4 key购买 nike

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

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com