简体   繁体   English

如何在设置中检查iPhone键盘Klick声音的开/关?

[英]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. 谢谢。

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. 我不知道这是否真的算作“私有API”,所以如果你使用这种方法,请准备拒绝。

The keyboard click sound settings is stored in the shared com.apple.preferences.sounds preference. 键盘单击声音设置存储在共享的com.apple.preferences.sounds首选项中。 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]; ) (顺便说一句:在UIKit中播放“点击”声音的实际调用是[UIHardware _playSystemSound:1104];

If you want to make the perfect solution, you should add the following lcode to your app. 如果您想制作完美的解决方案,您应该将以下lcode添加到您的应用程序中。 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. 如果有人告诉我如何评论这个网站,我会真的变得更有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM