0

私はiphoneを初めて使用しています。以下のコードで作業しています。ここでは、ローカル通知が10秒で起動せず、繰り返し間隔も機能しません。1秒ごとに通知が表示されません。同じように、繰り返し間隔は 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 に答える