简体   繁体   English

UILocalNotification不显示

[英]UILocalNotification not showing

My goal is to send the user local notifications while the app is in the background. 我的目标是在后台运行应用程序时向用户发送本地通知。 I've started testing out local notifications without success. 我已经开始测试本地通知,但没有成功。 I've tried adding this [self initializeNotification]; 我尝试添加此[self initializeNotification]; inside a UIButton action. UIButton动作中。

The debugger enters the alarm if but the notification is not showing. 如果调试器输入警报,但未显示通知。

-(void) initializeNotification
{
    UILocalNotification *alarm = [[UILocalNotification alloc] init];
    if (alarm)
    {
        NSLog(@"Bla");
        alarm.fireDate = nil;
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"alarmsound.caf";
        alarm.alertBody = @"Test message...";
        [[UIApplication sharedApplication] scheduleLocalNotification:alarm];
    }

The fire date is interpreted according to the value specified for timeZone . 根据为timeZone指定的值来解释触发日期。 If the specified value is nil or is a date in the past, the notification is delivered immediately. 如果指定的值为nil或过去的日期,则将立即发送通知。 And, when your app is active, the localNotification not present, it onley call the delegate 而且,当您的应用处于活动状态时, localNotification不存在,它会立即调用delegate

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

So, if you want see the notification in MessageCenter , you must set a fireDate 因此,如果要在MessageCenter查看通知,则必须设置fireDate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM