-->

如何开启/关闭飞行模式在IOS 5.1使用私有API(How to turn on/off airp

2019-06-24 04:14发布

我试图切换使用私人框架,IOS 5.1 /关闭飞行模式。

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

./AppSupport.framework/RadiosPreferences.h:

@property BOOL airplaneMode;

./AppSupport.framework/RadiosPreferences.h:

- (void)setAirplaneMode:(BOOL)arg1;

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

Answer 1:

作为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是在飞机模式偏好实际存储的文件,所以这就是你需要写访问什么。

,你不需要使用dlopendlsym访问此API。 您可以AppSupport框架直接(与例外添加到您的项目AppSupport.framework是根据存储在您的Mac上PrivateFrameworks文件夹)。 然后,只需实例化一个RadiosPreferences对象,并正常使用。 该权利是重要的组成部分。

为了您的代码,第一次使用类转储 ,或类转储-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

我只测试了这一个越狱的应用程序。 我不知道这是否是可能的,如果设备没有越狱获得这种权利(见维克多罗宁的评论)。 但是,如果这是一个越狱的应用程序,请确保您还记得权利文件签名的可执行文件。 我通常签订越狱应用LDID ,所以如果我的权利文件entitlements.xml,然后建立在Xcode后代码签名 ,我将执行

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

下面是Saurik公司的有关代码签名和权利页



Answer 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


文章来源: How to turn on/off airplane mode in IOS 5.1 using private API