iOS 设备静音时是否可以播放本地通知声音

发布于 2024-10-07 20:23:40 字数 88 浏览 12 评论 0原文

我正在开发闹钟,当收到本地通知时需要唤醒。但是当设备静音时我听不到任何声音,我之所以这么问是因为我看到有两个应用程序实现了该功能,即(无线电警报)。 谢谢,托默。

I'm developing alarm clock which needs to wake up when receiving local notification. but when the device on mute I cannot hear anything, I'm asking because I saw 2 apps which implemented that i.e (radio alarm).
thanks, tomer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悟红尘 2024-10-14 20:23:40

查看 AVAudioSessionsetCategory 函数——它应该可以满足您的需要。

以下是有关类别信息的链接:开发人员.apple.com - 音频会话类别

Check out AVAudioSession's setCategory function -- it should do the trick for you.

Here's a link for info on the categories: developer.apple.com - Audio Session Categories

寂寞笑我太脆弱 2024-10-14 20:23:40

我几乎可以肯定,RadioAlarm 能够在静音时播放,因为它会在后台运行。对于正常的本地通知(即即使在应用程序完成后也会触发的通知),我还没有找到一种方法来克服静音开关或铃声音量。

RadioAlarm, I'm almost certain, is able to play when muted because it keeps itself running in the background. For a NORMAL local notification (i.e. one that fires even after the app finishes), I have not found a way to overcome the mute switch or the ringer volume.

定格我的天空 2024-10-14 20:23:40
 -(void)playSound:(NSString *)filePath
    {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: nil];
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath]];
        [playerItem addObserver:self forKeyPath:@"status" options:0 context:0];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
        self.audioPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
        [self.audioPlayer play];
    }
 -(void)playSound:(NSString *)filePath
    {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: nil];
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath]];
        [playerItem addObserver:self forKeyPath:@"status" options:0 context:0];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
        self.audioPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
        [self.audioPlayer play];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文