如何在iOS 7上获得拨号盘提示音

时间:2014-04-12 07:33:59

标签: ios7 uibutton

如何在iOS 7上获得拨号盘提示音。

我的应用程序中有一个拨号盘,想要使用iOS 7拨号盘声音。就像这个图 enter image description here

我尝试了其他一些方法但不合适,并且在设备静音时声音不会减少。

谢谢。

2 个答案:

答案 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

之上或之下的.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);
}

答案 1 :(得分:1)

一个人可以使用以下简单的声音技巧。

NSUInteger toneID = 1200 + value;
AudioServicesPlaySystemSound((SystemSoundID)toneID);

value是从0到11的数字。

0-9代表小键盘数字,10代表星号,11代表哈希。

请注意,Apple在AppStore中接受此代码没有任何问题。从2014年至今,我的许多应用程序都在AppStore上运行。