【问题标题】:iOS switch off vibrate on silent programmatically [Private API]iOS 以编程方式在静音时关闭振动 [Private API]
【发布时间】:2013-10-19 22:50:04
【问题描述】:

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

谢谢,

弗洛

【问题讨论】:

    标签: ios settings iphone-privateapi vibration


    【解决方案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。

    希望有帮助!

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 在 Xcode 6.2 中尝试此操作时,我收到“函数 'notify_post' 的隐式声明在 C99 中无效”(Swift 项目与 Objective-C 的桥接头)编辑:也在 Obj-C 项目中.
      • 这仍然对您有用吗?我似乎无法完成这项工作
      【解决方案3】:

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

      这需要

      #include <notify.h>
      

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

      Apple doc's about notify.h

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-09
        • 1970-01-01
        • 1970-01-01
        • 2021-07-13
        • 2014-04-01
        • 2018-02-21
        • 1970-01-01
        相关资源
        最近更新 更多