1

How to check a system vibration is on or off by pogramatically through App? In my case UI design is like- I set a button into viewcontroller. Which funcanality is, when I press the button it's alert me the system vibration is On or Off. Here is the below code. But it's not working. It's always go with else part.

- (IBAction)checkVibrate:(id)sender {
 CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

if(CFStringGetLength(state) == 0)
{
    //off
    [self Alert:@"It seems that your phone's vibration is off. Please go to your phone setting and make the vibration ON"];
}
else
{
    //on
    [self Alert:@"It seems that your phone's vibration is On.If you want to off the vibration, please go to device setting and make vibration Off"];
}

}

If I go through wrong way,please help me out with this topic?

Abir
  • 31
  • 7
  • @user3182143 , i know it's a duplicate question. But I am trying to implement this topic through [https://stackoverflow.com/questions/5519807/iphone-how-do-i-know-if-the-vibrate-is-on-or-off-for-ios]. That time I am not getting exact output. So Please help me out – Abir Oct 03 '17 at 15:25
  • I added all sources below. – user3182143 Oct 03 '17 at 15:26

2 Answers2

0

No, you cannot. Apple is not providing the API to access this.

Himanth
  • 2,381
  • 3
  • 28
  • 41
  • What I mean to say that, I want only check the mode of vibration(On or Off), not to want the change of vibration mode. – Abir Oct 03 '17 at 15:07
0

Once I saw your question, I tried to get the solution.I prepared most of the other answer in the stack overflow and other sites.All tell to use AVAudioSession

An audio session acts as an intermediary between your app and the operating system—and in turn, the underlying audio hardware. You use it to communicate to the operating system the nature of your app’s audio without detailing the specific behavior or required interactions with the audio hardware. This delegates the management of those details to the audio session, which ensures that the operating system can best manage the user’s audio experience.

Better Sources are

How to detect whether iPhone is vibrating or not?

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

iPhone Vibration

Making the iPhone Vibration

Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

user3182143
  • 9,459
  • 3
  • 32
  • 39