如何在iOS 7上发出拨号盘蜂鸣音。
我的应用程序中有一个拨号盘,并希望使用iOS 7拨号盘sound.The one,如图所示

我尝试了一些其他方法,但不合适,声音不会在设备静音时减少。
谢谢。
发布于 2014-04-15 00:26:45
首先,在音频盒中导入.wav音频文件0到9,并正确命名它们,就像我在这里为像DTMF_00.wav到DTMF_09.wav这样的文件编写代码一样,所以你必须按你的意愿命名这个文件,但请记住,你必须更改NSString *toneFilename = [NSString stringWithFormat:@"DTMF_%02d", count];这一行,并给出你的文件名。
然后你必须在viewController.h中使用#import <AudioToolbox/AudioToolbox.h>命令
在.h文件中,在接口{}中声明SystemSoundID toneSSIDs[10];,如下所示
@interface yourViewController : UIViewController{ SystemSoundID toneSSIDs[10]; }
在头文件中设置一个按钮动作事件,并将其设置为所有按钮。(请记住,不要为单个按钮创建动作事件,您只需创建一个单击事件)
然后,您必须在- (void)viewDidLoad上方或下方的.m文件中编写以下代码
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if(self)
{
for(int count = 0; count < 10; count++){
NSString *toneFilename = [NSString stringWithFormat:@"DTMF_%02d", count];
NSURL *toneURLRef = [[NSBundle mainBundle] URLForResource:toneFilename withExtension:@"wav"];
SystemSoundID toneSSID = 0;
AudioServicesCreateSystemSoundID((__bridge CFURLRef) toneURLRef,&toneSSID);
toneSSIDs[count] = toneSSID;
}
}
return self;
}然后
-(IBAction)numberButtonPressed:(UIButton *)pressedButton
{
int toneIndex = [pressedButton.titleLabel.text intValue];
SystemSoundID toneSSID = toneSSIDs[toneIndex];
AudioServicesPlaySystemSound(toneSSID);
}发布于 2018-07-26 03:21:58
你可以使用下面这个简单的声音技巧。
NSUInteger toneID = 1200 + value;
AudioServicesPlaySystemSound((SystemSoundID)toneID);这里的value是一个从0到11的数字。
0-9表示键盘数字,10表示星号,11表示散列。
请注意,苹果在AppStore中接受此代码没有任何问题。从2014年到现在,我的许多应用程序都运行在AppStore上。
https://stackoverflow.com/questions/23027598
复制相似问题