我是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];
}
答案 0 :(得分:0)
您需要在appDelegate中实现此功能,以便在应用运行时通知正常工作。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
//do something
}