gpt4 book ai didi

ios - 设备处于静音模式时播放声音

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:31:59 36 4
gpt4 key购买 nike

我是编码应用程序的新手,我创建了一个播放声音的简单应用程序。我已经测试过了,它工作得很好。但是,我想在静音模式下播放声音。

代码如下:

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController

-(IBAction)Button1Sound:(id)sender{
AudioServicesPlaySystemSound(Button1);
}

- (void)viewDidLoad {
NSURL *Button1Sound = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"nobody" ofType:@"m4a"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)Button1Sound, & Button1);

[super viewDidLoad];
}

@end

网上看了其他问题,说要加上这行代码:

[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];

我不确定把它放在哪里或者我是否使用了正确的语法。我也在使用 audiotoolbox 框架。

最佳答案

在静音模式下,除非用户明确启动声音播放,例如媒体播放,否则将违反人机界面指南 (HIG),是应用被拒绝的理由。

根据 HIG :

Silence. People switch their device to silent to avoid being interrupted by unexpected sounds, such as ringtones and incoming message sounds. They also want nonessential sounds disabled, including keyboard sounds, sound effects, game soundtracks, and other audible feedback. When the device is set to silent, only explicitly initiated sounds should occur, such as audio during media playback, alarms, and audio/video messaging.

如果您觉得您的需求没有违反,请参阅此 post寻求解决方案。

关于ios - 设备处于静音模式时播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40900502/

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