Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

cocoa touch - iPhone - How do I know if the vibrate is on or off for iOS?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...