13

Do you know how I may know if the iPhone is on vibrate mode ? I don't find anything about this on the Web... Too tired to see ?

I want to display an icon in the app so that the user can know looking at it if the phone is on vibrate mode or not. Tha app has also different behaviours depending on if the user wants to be disturbed (vibrate off) or not (vibrate on).

Thank you.

Oliver
  • 23,072
  • 33
  • 138
  • 230
  • 1
    I know I shouldn't, but... *snicker* – Mitch Lindgren Apr 01 '11 at 23:22
  • What are you trying to achieve by knowing it's on vibrate mode? For audio playback? – iwasrobbed Apr 02 '11 at 00:22
  • @iWasRobbed : I want to display an icon in the app so that the user can know looking at it if the phone is on vibrate mode or not. – Oliver Apr 02 '11 at 01:04
  • Not sure that the visual indicator is really necessary. You shouldn't really ever need to know. You simply give commands to the OS and then it responds depending on the hardware state. – FreeAsInBeer Apr 02 '11 at 01:07
  • @FreeAsInBeer : May I describe the whole application stuff ? It does not only show an indicator. It has different behaviours depending on the fact that the user want to be disturbed or not. – Oliver Apr 02 '11 at 01:11
  • So just put an option in your app to act in silent mode. – Black Frog Apr 02 '11 at 01:23

1 Answers1

11

You should be able to achieve this using:

#import "AudioToolbox/AudioToolbox.h"

- (void) ifSilentModeThenShowIcon
{
   CFStringRef state;
   UInt32 propertySize = sizeof(CFStringRef);
   AudioSessionInitialize(NULL, NULL, NULL, NULL);
   AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

   if(CFStringGetLength(state) == 0)
   { 
     // phone's ringer is off so put
     // some icon showing code here
   }
}

Source

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
  • Nice find. I'm assuming this is safe for the App Store? – sudo rm -rf Apr 02 '11 at 01:30
  • Yes, these are just audio session properties so it is public API. More info here: http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html – iwasrobbed Apr 02 '11 at 02:06
  • AudioSessionInitialize and AudioSessionGetProperty are deprecated in iOS 7, is there another way to do this? – easythrees Jan 12 '14 at 21:35