@property BOOL airplaneMode;
./AppSupport.framework/RadiosPreferences.h:
:- (void)setAirplaneMode:(BOOL)arg1;
我该如何使用这些方法?我需要使用dlsym
来创建对象并调用方法吗?有人能帮我提供示例代码或实现方法吗?
@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
并将其设置为 true(您可能需要创建清单)。我相信以下内容应该可以工作-如果不行,我晚上测试后再看:
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