Newbee
Newbee

Reputation: 1032

How to check iPhone keyboard klick sound turned on/off in settings?

I'm working on custom keyboard and need to play tap sound for keys if it enabled in the Settings. Tap sound not a problem but how to check is keyboard click sound enabled ? Thanks.

Upvotes: 13

Views: 1976

Answers (2)

Hrissan
Hrissan

Reputation: 184

If you want to make the perfect solution, you should add the following lcode to your app. Otherwise after the first read, the setting is cached, and if the user switches to settings, makes change and switches back, we should re-read the cached value. :)

- (void)applicationWillEnterForeground:(UIApplication *)application {
CFPreferencesAppSynchronize(CFSTR("/var/mobile/Library/Preferences/com.apple.preferences.sounds"));

If someone tells me how to comment on this site I would really become more helpful.

Upvotes: 4

kennytm
kennytm

Reputation: 523374

There's no documented way to check this, but it's possible. I don't know if this really counts as "private API", so be prepared for rejection if you use this method.

The keyboard click sound settings is stored in the shared com.apple.preferences.sounds preference. So you could try

return CFPreferencesGetAppBooleanValue(
        CFSTR("keyboard"),
        CFSTR("/var/mobile/Library/Preferences/com.apple.preferences.sounds"),
        NULL);

(BTW: the actual call to play the "click" sound in UIKit is [UIHardware _playSystemSound:1104];)

Upvotes: 17

Related Questions