HJo*_*n35 1 timezone uiapplication ios uilocalnotification ios-simulator
我正在尝试合并在一定时间间隔后触发的本地通知,但是,在使用模拟器进行测试时,我似乎无法在任何时候显示通知.
我只是想在创建后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];
Run Code Online (Sandbox Code Playgroud)
//这是我的app委托中的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];
}
Run Code Online (Sandbox Code Playgroud)
1)您是否已注册使用通知? 你可以通过错过这个简单的步骤来看到我在这里面对的内容.它在Swift中,但你得到了要点:UILocalNotification没有做任何事情
2)当你在应用程序内部时,我认为通知不起作用,因为它违背了通知的目的.当您不在应用程序即后台模式或终止时,通知应该提醒您.因此,在进行测试时,请确保您不在应用中
3)通常,根据我的经验,测试通知最好在模拟器上完成.
| 归档时间: |
|
| 查看次数: |
3021 次 |
| 最近记录: |