我想在核心位置框架委托(delegate)方法触发时在我的 IOS 设备中触发警报。当应用程序位于前台时,警报会正常响起。但是当设备被锁定时,警报功能不起作用。这是我用过的代码。
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = @"body";
localNotification.soundName = @"RING.WAV";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
是不是因为我使用了UILocalNotification类?如果是这样,是否有替代方案。
锁屏界面显示本地通知提示体,但不响闹。
编辑:
在 appdelegate 中,我有代表接收本地通知
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notification{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/RING.WAV", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
if (audioPlayer == nil)
NSLog(@"error :%@",[error description]);
else
[audioPlayer play];
}
我发现设备锁定时不会触发此方法。有没有办法在设备锁定时触发基于 UILocalNotification 的警报?
最佳答案
你需要告诉手机你的通知有 Action
[localNotification setAlertAction:@"My Action"];
[localNotification setHasAction:YES];
关于ios - 设备锁定时警报不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21531681/