如何在iOS 7上获得拨号盘提示音。
我的应用程序中有一个拨号盘,想要使用iOS 7拨号盘声音。就像这个图
我尝试了其他一些方法但不合适,并且在设备静音时声音不会减少。
谢谢。
答案 0 :(得分:2)
首先在音频框中导入.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
-(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);
}
答案 1 :(得分:1)
一个人可以使用以下简单的声音技巧。
NSUInteger toneID = 1200 + value;
AudioServicesPlaySystemSound((SystemSoundID)toneID);
value
是从0到11的数字。
0-9代表小键盘数字,10代表星号,11代表哈希。
请注意,Apple在AppStore中接受此代码没有任何问题。从2014年至今,我的许多应用程序都在AppStore上运行。