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
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.
As Farzad Nazifi mentioned above Allow openAcesess
after a fresh install , solved my issue .
And I recommend a simpler solution for playing system keyboard tap sound
Swift and Objective-C All the same `we don't need to import any custom sound file just play the system tap sound.
Import AudioToolbox framework:
#import <AudioToolbox/AudioToolbox.h>
AudioServicesPlaySystemSound(1104)
This code is tested in iOS 8 beta 5 , I hope apple would fix the bug (if it is a bug) in the GM version .
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);
}
I have implemented and verified this method works on both simulators and devices on iOS8 Beta 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With