How to play tock sound when tapping custom keyboard buttons

后端 未结 6 755
闹比i
闹比i 2020-12-29 16:09

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

6条回答
  •  鱼传尺愫
    2020-12-29 17:02

    Playing sounds requires OpenAccess, I don't know why Apple is doing it like this but it is what it is for now. This will also fix the lag and issues with it not working after trying to play the sound.

    You can get OpenAccess by setting YES for the value of RequestsOpenAccess Key in the info.plist of the keyboard.

    Next you should import AudioToolbox to your project, then use this code:

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

    Now install your keyboard and give the Openaccess while adding it to your keyboards and it should work.

提交回复
热议问题