【问题标题】:How to turn on/off airplane mode in IOS 5.1 using private API如何使用私有 API 在 IOS 5.1 中打开/关闭飞行模式
【发布时间】:2012-05-14 05:21:12
【问题描述】:

我正在尝试使用私有框架在 IOS 5.1 中打开/关闭飞行模式。

在 AppSupport.framework 中,RadiosPreferences 具有获取/设置飞行模式和设置值的属性

./AppSupport.framework/RadiosPreferences.h

@property BOOL airplaneMode;

./AppSupport.framework/RadiosPreferences.h

- (void)setAirplaneMode:(BOOL)arg1;

如何使用这些方法?我是否需要以某种方式使用dlsym 来创建对象并调用方法?有人可以帮助我提供示例代码或方法。

【问题讨论】:

  • 你有想过这个吗?

标签: iphone ios iphone-privateapi


【解决方案1】:

作为jrtc27 describes in his answer(和I mentioned here),您需要为您的应用授予特殊权利,以便成功更改airplaneMode 属性。

这是一个要添加到项目中的示例 entitlements.xml 文件:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.SystemConfiguration.SCDynamicStore-write-access</key>
    <true/>
    <key>com.apple.SystemConfiguration.SCPreferences-write-access</key>
    <array>
        <string>com.apple.radios.plist</string>
    </array>
</dict>
</plist>

com.apple.radios.plist 是实际存储飞行模式首选项的文件,因此您需要对其进行写访问。

,您无需使用dlopendlsym 即可访问此API。您可以直接将 AppSupport 框架添加到您的项目中(AppSupport.framework 存储在您的 Mac 上的 PrivateFrameworks 文件夹下除外)。然后,只需实例化一个RadiosPreferences 对象,就可以正常使用了。权利是重要的部分。

对于您的代码,首先use class-dumpclass-dump-z 生成 RadiosPreferences.h 文件,并将其添加到您的项目中。那么:

#import "RadiosPreferences.h"

然后做

RadiosPreferences* preferences = [[RadiosPreferences alloc] init];
preferences.airplaneMode = YES;  // or NO
[preferences synchronize];
[preferences release];           // obviously, if you're not using ARC

我只为越狱应用测试过这个。如果设备没有越狱,我不确定是否可以获得此权利(请参阅 Victor Ronin 的评论)。但是,如果这是一个越狱应用程序,请确保您记得授权文件签署您的可执行文件。我通常使用ldid 签署越狱应用程序,所以如果我的权利文件是entitlements.xml,那么在Xcode without code signing 构建后,我会执行

ldid -Sentitlements.xml $BUILD_DIR/MyAppName.app/MyAppName

Here's Saurik's page on code signing, and entitlements

【讨论】:

  • 我可以确认它适用于 iOS 6.1。此外,确保嵌入式权利 xml 使用 UNIX 行终止,否则内核将无法运行应用程序。
  • @Zmaster 您是否也确认这不适用于未入狱的破手机?
  • @Lolo 如果您正在谈论在 AppStore 应用程序上使用它,那么这绝对是不可能的。您需要同时包含 AppSupport(一个私有框架)并添加权利(也是保留的):如果您这样做,您的应用将被拒绝。
  • 不,我实际上只是想在我的个人手机上使用它,即将它从 xcode 上传到我的 iphone。我已经放弃了通过应用商店销售应用来致富的希望,但我还没有准备好入狱打破我全新的 iPhone 只是为了看看我是否可以让它发挥作用。
  • @Lolo,抱歉延迟回复。不,如果没有越狱设备,您将无法执行此操作。
【解决方案2】:

com.apple.SystemConfiguration.SCPreferences-write-access 添加到您的权利 plist 并将其设置为 true(您可能需要创建 plist)。我相信以下应该有效 - 如果不能,我可以在今晚晚些时候进行测试时查看:

NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/AppSupport.framework"];
BOOL success = [bundle load];

Class RadiosPreferences = NSClassFromString(@"RadiosPreferences");
id radioPreferences = [[RadiosPreferences alloc] init];
[radiosPreferences setAirplaneMode:YES]; // Turns airplane mode on

【讨论】:

  • “com.apple.SystemConfiguration.SCPreferences-write-access”权限超出了私有 API。它仅在越狱设备上可用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多