iPhone: programmatically check if vibration is enabled
Asked Answered
C

2

1

Is it possible to programmatically check if the system option of iPhone

Settings -> Sounds -> Vibrate on Ring

is enabled?

In my app, I would like to display an alert to the user if that option is disabled.

Choochoo answered 10/10, 2013 at 12:15 Comment(0)
S
1

You cannot. Because apple is not providing the API to access the iPhone settings app.

Shana answered 10/10, 2013 at 12:25 Comment(0)
D
-1

may be you could give it a try and make sure you're running the app in iDevice because simulator don't have silent or ring mode :)

New Edits

-(BOOL)silenced 
{
     #if TARGET_IPHONE_SIMULATOR
        // return NO in simulator. Code causes crashes for some reason.
     return NO;
     #endif

    CFStringRef state;
    UInt32 propertySize = sizeof(CFStringRef);
    AudioSessionInitialize(NULL, NULL, NULL, NULL);
    AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
    if(CFStringGetLength(state) > 0)
        return NO;
    else
        return YES;
}

and you can call this method like this way

if ([self silenced]) 
{
    NSLog(@"silenced");
} else {
    NSLog(@"not silenced");
}

hope it will help you!

Dignitary answered 10/10, 2013 at 12:23 Comment(1)
I tested the algorithm with vibration on/off and with the silent switch on/off, but the value of "state" is @"Speaker" in all 4 cases... (tested on iPhone 5, iOS 7.0.2).Choochoo

© 2022 - 2024 — McMap. All rights reserved.