Are there any other iOS system sounds available other than 'tock'?

后端 未结 2 1339
半阙折子戏
半阙折子戏 2020-12-14 19:29

I have implemented an alternative keyboard on my first iPhone app. I would like to play a sound when a button is pressed. The default click sound when the standard keyboard

相关标签:
2条回答
  • 2020-12-14 20:03

    Try UIDevice's playInputClick:

    [[UIDevice currentDevice] playInputClick];
    

    From the documentation:

    Use this method to play the standard system keyboard click in response to a user tapping in a custom input or keyboard accessory view. A click plays only if the user has enabled keyboard clicks in Settings > Sounds, and only if the input view is itself enabled and visible.

    Make sure you adopt the UIInputViewAudioFeedback protocol in your input view class, and implement the enableInputClicksWhenVisible delegate method to return YES, as per the documentation.

    EDIT - For implementation of delegate methods, check out Apple's documentation on custom input views.

    0 讨论(0)
  • 2020-12-14 20:15

    Prior to, and since posting this question almost 2 weeks ago I have searched high and low for a method to make the keyboard click sound work in my app. I have attempted to implement and understand Apple's documentation on custom input views. I butchered my app in many ways attempting to make it work and created several test projects. I tried to interpret how to do this from various other sources on the web. All to no avail. I have finished my app all but for this last function.

    I finally hit on a simple answer towards the end of this IPhone Dev SDK form question/post. The ultimate answer is easy and can be done in a few seconds with these easy steps.

    1. Link the 'AudioToolbox.framework' to your project (Click on your project's Target, select 'Build Phases' and under the 'Link Binary with Libraries' item click the + button and add the framework.

    2. Add the following to the header file of the class where you want to implement the click:

      #import <AudioToolbox/AudioToolbox.h>
      
    3. Add the following line of code in the implementation file of your class wherever you want the keyboard click sound to appear:

      AudioServicesPlaySystemSound(0x450);
      

    THAT'S IT! AND IT WORKED!!! HALLELUJAH!

    According to Paul in the other forum this has the following downside:

    "keyboard keys won't be affected by the iOS user preference for keyboard sound on/off."

    But when I turn the volume up or down on my iPhone or if I mute the iPhone, the keyboard click sounds do go up and down or are muted as would be expected. Given that I found it impossible to implement keyboard clicks "UIInputViewAudioFeedback" as documented, I'm happy to have anything work.

    P.S. If anyone has a link to an actual project that I can download, build and run on my iPhone to see EXACTLY how to properly implement: "UIInputViewAudioFeedback" I'd be happy to give it a look. But so far I've found none, nor any step-by-step newbie style instructions on how to make it work.

    [Sept 30, 2012 UPDATE:] I'm happy to say that my app was accepted into the app store using this method. Here it is: https://itunes.apple.com/app/fine-tip-tip-calculator/id563429225

    ...Dale

    0 讨论(0)
提交回复
热议问题