iOS switch off vibrate on silent programmatically [Private API]

空扰寡人 提交于 2019-12-03 14:30:33

I think the following code can do the trick. You need to trigger it from somewhere though (haven't understand if you want it to be fired with the button or from within an app).

NSString *sbPath = @"/var/mobile/Library/Preferences/com.apple.springboard.plist";
NSMutableDictionary *sbDict = [[NSMutableDictionary alloc] initWithContentsOfFile:sbPath];
[sbDict setValue:[NSNumber numberWithBool:NO] forKey:@"silent-vibrate"];
[sbDict writeToFile:filePath atomically: YES];
notify_post("com.apple.SpringBoard/Prefs");

Haven't tried it myself, but found something like what you are looking for in the Smartvibrate tweak. This will change the settings parameter, so you should change it back to on when your application finishes.

Hope that helps!

Baptiste Truchot

Update for ios 8 :

NSMutableDictionary *dict; BOOL newState = NO;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
dict = [[defaults persistentDomainForName:@"com.apple.springboard"] mutableCopy] ?:           [[NSMutableDictionary alloc] init];
NSNumber *value = [NSNumber numberWithBool:newState];
[dict setValue:value forKey:@"ring-vibrate"];
[dict setValue:value forKey:@"silent-vibrate"];
[defaults setPersistentDomain:dict forName:@"com.apple.springboard"];
notify_post("com.apple.springboard.ring-vibrate.changed");
notify_post("com.apple.springboard.silent-vibrate.changed");

Update to @baptiste-truchot 's answer (and @vrwim 's concern):

This needs

#include <notify.h>

at top of the .h file associated.

Apple doc's about notify.h

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