如何使用私有API在IOS 5.1中打开/关闭飞行模式 [英] How to turn on/off airplane mode in IOS 5.1 using private API

查看:426
本文介绍了如何使用私有API在IOS 5.1中打开/关闭飞行模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to toggle on/off airplane mode in IOS 5.1 using private frameworks.

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

In AppSupport.framework, RadiosPreferences has a property to get/set the airplane mode and set the value

./ AppSupport.framework / RadiosPreferences.h

@property BOOL airplaneMode;

./ AppSupport.framework / RadiosPreferences.h

- (void)setAirplaneMode:(BOOL)arg1;

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

How can I use these methods? Do I need to use dlsym somehow to create an object and call the methods? Can someone help me with sample code or ways to do it.

推荐答案

jrtc27在他的描述回答(以及我在这里提到),您需要为您的应用授予特殊权利才能成功更改 airplaneMode 属性。

As jrtc27 describes in his answer (and I mentioned here), you need to grant your app a special entitlement in order to successfully change the airplaneMode property.

以下是要添加到您的示例entitlements.xml文件project:

Here's a sample entitlements.xml file to add to your project:

<!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 是飞机模式所在的文件偏好实际上是存储的,因此您需要写入权限。

com.apple.radios.plist is the file where the airplane mode preference is actually stored, so that's what you need write access to.

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

No, you don't need to use dlopen or dlsym to access this API. You can add the AppSupport framework to your project directly (with the exception that AppSupport.framework is stored on your Mac under the PrivateFrameworks folder). Then, just instantiate a RadiosPreferences object, and use it normally. The entitlement is the important part.

对于您的代码,首先使用类转储,或 class-dump-z ,生成RadiosPreferences.h文件,并将其添加到项目中。然后:

For your code, first use class-dump, or class-dump-z, to generate the RadiosPreferences.h file, and add it to your project. Then:

#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中构建 没有代码签名,我会执行

I've only tested this for a jailbroken app. I'm not sure if it's possible to acquire this entitlement if the device isn't jailbroken (see Victor Ronin's comment). But, if this is a jailbreak app, make sure you remember to sign your executable with the entitlements file. I normally sign jailbreak apps with ldid, so if my entitlements file is entitlements.xml, then after building in Xcode without code signing, I would execute

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

这是Saurik关于代码签名和权利的页面

这篇关于如何使用私有API在IOS 5.1中打开/关闭飞行模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆