[英]How to turn on/off airplane mode in IOS 5.1 using private API
我正在尝试使用私有框架在IOS 5.1中打开/关闭飞行模式。
在AppSupport.framework中, RadiosPreferences
具有获取/设置飞行模式并设置值的属性
./AppSupport.framework/RadiosPreferences.h :
@property BOOL airplaneMode;
./AppSupport.framework/RadiosPreferences.h :
- (void)setAirplaneMode:(BOOL)arg1;
我该如何使用这些方法? 我是否需要以某种方式使用dlsym
创建一个对象并调用方法? 有人可以帮我提供示例代码或方法。
正如jrtc27在他的回答 ( 我在这里提到 )中所描述的那样 ,您需要为您的应用授予特殊权利才能成功更改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是实际存储飞行模式首选项的文件,因此您需要写入访问权限。
不 ,您不需要使用dlopen
或dlsym
来访问此API。 您可以AppSupport框架直接(与例外添加到您的项目AppSupport.framework
是根据存储在您的Mac上PrivateFrameworks
文件夹)。 然后,只需实例化RadiosPreferences
对象,并正常使用它。 权利是重要的部分。
对于您的代码,首先使用class-dump或class-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中构建之后,我会执行
ldid -Sentitlements.xml $BUILD_DIR/MyAppName.app/MyAppName
添加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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.