7

我想让我的 iPhone 在静音模式下保持振动,即使它在设置中打开也是如此。我想从一个应用程序以编程方式完成它。这是给我的,所以我可以使用私有 API。是否有在设置中管理声音的 api?你知道有什么解决办法吗?

谢谢,

弗洛

4

3 回答 3

1

我认为以下代码可以解决问题。不过,您需要从某个地方触发它(不知道您是希望它通过按钮触发还是从应用程序中触发)。

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");

我自己还没有尝试过,但在Smartvibrate调整中找到了您正在寻找的东西。这将更改设置参数,因此您应该在应用程序完成后将其更改回 on。

希望有帮助!

于 2013-10-31T16:05:25.783 回答
0

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");
于 2015-01-08T12:20:16.980 回答
0

更新@baptiste-truchot 的答案(以及@vrwim 的关注):

这需要

#include <notify.h>

在关联的 .h 文件的顶部。

Apple 文档关于 notify.h

于 2017-11-26T21:00:03.047 回答