点击自定义键盘按钮时如何播放铃声

How to play tock sound when tapping custom keyboard buttons(点击自定义键盘按钮时如何播放铃声)
本文介绍了点击自定义键盘按钮时如何播放铃声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

一段时间以来,我一直在为 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. 使用音频工具箱
  2. 使用 AVFoundation
  3. 将 tock.caf 放入我的包中即可播放

其中一些在模拟器中有效,但在我的设备中均无效.在点击自定义键盘按钮时成功播放声音的任何人都可以分享一些工作代码吗?如果代码能够尊重声音设置,那就最好了.

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 thread的回答.

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to resize UITextView on iOS when a keyboard appears?(出现键盘时如何在iOS上调整UITextView的大小?)
How to reliably detect if an external keyboard is connected on iOS 9?(如何可靠地检测 iOS 9 上是否连接了外部键盘?)
How to mimic Keyboard animation on iOS 7 to add quot;Donequot; button to numeric keyboard?(如何在 iOS 7 上模拟键盘动画以添加“完成数字键盘的按钮?)
How do I dismiss the iOS keyboard?(如何关闭 iOS 键盘?)
Is possible to simulate touch event using an external keyboard on ios jailbroken?(是否可以在 ios 越狱后使用外部键盘模拟触摸事件?)
How do I retrieve keystrokes from a custom keyboard on an iOS app?(如何从 iOS 应用程序上的自定义键盘检索击键?)