当应用程序未运行时,我尝试每 n 分钟运行一些功能。 我认为本地通知适合于此,但我有一个问题。
如果我将本地通知设置为:
-(void)notification{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = [[NSDate date] dateByAddingTimeInterval:15];
//localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif.alertBody = @"marko";
// Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
每次都会触发通知,然后执行以下操作:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
NSLog(@"Recieved Notification %@",notif);
}
我想要的是在 15 秒后首先触发一些函数,如果函数返回 YES,则播放声音并在其上放置角标(Badge)。
怎么做?
最佳答案
如果系统发送通知时应用程序位于最前面并且可见,则不会显示任何警报,不会标记任何图标,并且不会播放任何声音。但是,如果应用程序委托(delegate)实现了 application:didReceiveLocalNotification: ,则会调用它。
确保您正在设备中进行测试。
关于ios 火灾前本地通知检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16476809/