iPhone: programmatically check if vibration is enabled

匆匆过客 提交于 2019-12-08 10:37:51

问题


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.


回答1:


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




回答2:


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!



来源:https://stackoverflow.com/questions/19295480/iphone-programmatically-check-if-vibration-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!