如何攻自定义键盘按钮时播放声音滴答 [英] How to play tock sound when tapping custom keyboard buttons

查看:247
本文介绍了如何攻自定义键盘按钮时播放声音滴答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经工作的自定义键盘上针对iOS 8一段时间,一切正常,到目前为止,但我还是不能让我的头围绕此点击音的东西。

I've been working on a custom keyboard for iOS 8 for some time and everything went fine so far, but I still couldn't get my head around this tapping sound stuff.

我搜索高和低这个问题,并尝试了多种方法,包括

I searched high and low for this issue and tried several approaches including


  1. 使用AudioToolbox

  2. 使用AVFoundation

  3. 把我的包里面的tock.caf,只是玩

他们中的一些作品,在模拟器,但他们都不在我的设备的工作原理。
任何人都可以自定义键盘按钮时,窃听谁成功播放的声音关心分担一些工作code?它是最好的,如果在code可以兑现的声音设定。

Some of them works, in the simulators but none of them works in my devices. Could anyone who has successfully played sound when tapping on custom keyboard buttons care to share some working code? And it is the best if the code could honor the sound settings.

推荐答案

最后,我从其他SO 线程答案

Finally I got an answer from other SO thread.

- (void)playSound
{
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Tock" ofType:@"caf"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
    AudioServicesPlaySystemSound (soundID);
}

我已经实现并验证该方法是基于对iOS8上的Beta 2版

I have implemented and verified this method works on both simulators and devices on iOS8 Beta 2.

这篇关于如何攻自定义键盘按钮时播放声音滴答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆