use*_*756 14 iphone iphone-privateapi ios
我正在尝试使用私有框架在IOS 5.1中打开/关闭飞行模式.
在AppSupport.framework中,RadiosPreferences有一个属性来获取/设置飞行模式并设置值
./AppSupport.framework/RadiosPreferences.h:
@property BOOL airplaneMode;
Run Code Online (Sandbox Code Playgroud)
./AppSupport.framework/RadiosPreferences.h:
- (void)setAirplaneMode:(BOOL)arg1;
Run Code Online (Sandbox Code Playgroud)
我该如何使用这些方法?我是否需要以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>
Run Code Online (Sandbox Code Playgroud)
com.apple.radios.plist是实际存储飞行模式首选项的文件,因此您需要写入访问权限.
不,您不需要使用dlopen或dlsym访问此API.您可以直接将AppSupport框架添加到项目中(除了AppSupport.framework存储在Mac上的PrivateFrameworks文件夹下).然后,只是实例化一个RadiosPreferences对象,并正常使用它.权利是重要的部分.
对于您的代码,首先使用class-dump或class-dump-z生成RadiosPreferences.h文件,然后将其添加到项目中.然后:
#import "RadiosPreferences.h"
Run Code Online (Sandbox Code Playgroud)
并做
RadiosPreferences* preferences = [[RadiosPreferences alloc] init];
preferences.airplaneMode = YES; // or NO
[preferences synchronize];
[preferences release]; // obviously, if you're not using ARC
Run Code Online (Sandbox Code Playgroud)
我只是为越狱应用测试了这个.如果设备没有越狱,我不确定是否有可能获得此权利(参见Victor Ronin的评论).但是,如果这是一个越狱应用程序,请确保您记得使用权利文件签署您的可执行文件.我通常用ldid签署越狱应用程序,所以如果我的权利文件是entitlements.xml,那么在没有代码签名的 Xcode中构建之后,我会执行
ldid -Sentitlements.xml $BUILD_DIR/MyAppName.app/MyAppName
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5117 次 |
| 最近记录: |