gpt4 book ai didi

ios - 警报(通知)声音突然在iO中停止工作

转载 作者:行者123 更新时间:2023-12-03 01:43:31 25 4
gpt4 key购买 nike

在我的应用中,您可以选择观看特定区域。越界时会发出通知。当应用程序在前台时显示为alertView和声音,而当应用程序在后台显示为带有警报声的通知。当应用程序在前台运行时,一切正常。在后台时,不会发出通知,也不会播放警报声。以前效果很好。

这是我的代码:

// Show alertview when active and show localNotification when inactive

-(void)AlertViewShow{

if (i == 1) {

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString (@"Alert",@"")
message:NSLocalizedString(@"AlertMoving",@"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"AlertOK",@"")
otherButtonTitles:nil];

[alert show];

NSURL *soundURL = [[NSBundle mainBundle]URLForResource: @"ALARM"
withExtension:@"WAV"];
avSound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
avSound.numberOfLoops = -1;
[avSound play];
}
i = 2;
}


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
if ([avSound isPlaying]) {
[avSound stop];
}
}
if (i == 2) {
[[UIApplication sharedApplication] cancelAllLocalNotifications];

}

}

- (void)localNotification {

UILocalNotification *localNotif = [[UILocalNotification alloc] init];

if (localNotif == nil)
return;
localNotif.fireDate = nil;
localNotif.alertBody = NSLocalizedString (@"NotifAlert",@"");
localNotif.alertAction = NSLocalizedString (@"NotifView",@"");
localNotif.soundName = @"ALARMSHORT.wav";
localNotif.applicationIconBadgeNumber = 0;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

}

// END Show alertview when active and show localNotification when inactive

有谁知道更改的内容,为什么它突然不起作用了?
感谢您的帮助。

最佳答案

您正在使用deprecated in iOS 10scheduleLocalNotification:。尝试更新为UNUserNotificationCenter,看看问题是否仍然存在。

关于ios - 警报(通知)声音突然在iO中停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45593442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com