0

我是 iphone 新手。我正在使用以下代码,这里本地通知不会在 10 秒内触发,并且重复间隔也不起作用,它不会每秒显示通知。在 1 分钟的触发呼叫和同样的方式重复间隔每分钟工作一次。如何将重复间隔设置为每 15 秒。如果有人知道这一点,请帮助我...

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"1");

   NSTimeInterval interval = 10;
    NSDate *alertTime = [NSDate dateWithTimeIntervalSinceNow:interval];
    UIApplication* app = [UIApplication sharedApplication];
    UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];
    if (notifyAlarm){
        notifyAlarm.fireDate = alertTime;

        notifyAlarm.alertAction = @"Message";
        notifyAlarm.alertBody = @"Alert";
        notifyAlarm.hasAction = YES;
        notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];

        notifyAlarm.repeatInterval = NSSecondCalendarUnit;
      //  timer = [[NSTimer alloc]initWithFireDate:alertTime interval:interval target:self selector:@selector(sendRequest) userInfo:nil repeats:YES];

        [app scheduleLocalNotification:notifyAlarm];

        }
4

1 回答 1

0

您需要在 appDelegate 中实现这一点,以便在应用程序运行时通知工作。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    //do something
}
于 2012-05-14T10:24:42.733 回答