14

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

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;

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.

Nate
  • 31,017
  • 13
  • 83
  • 207
user1165756
  • 375
  • 3
  • 11

2 Answers2

7

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.

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 is the file where the airplane mode preference is actually stored, so that's what you need write access to.

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.

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"

and do

RadiosPreferences* preferences = [[RadiosPreferences alloc] init];
preferences.airplaneMode = YES;  // or NO
[preferences synchronize];
[preferences release];           // obviously, if you're not using ARC

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

Here's Saurik's page on code signing, and entitlements

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • 2
    I can confirm that it works on iOS 6.1. Also, ensure that the embedded entitlements xml uses UNIX line terminations otherwise the kernel won't run the app. – Zmaster Jan 31 '13 at 16:37
  • @Zmaster Do you also confirm this won't work on a non-jailed broken phone? – Lolo Feb 13 '15 at 01:43
  • @Lolo If you're talking about using this on an AppStore app then it's definitely not possible. You need to both include AppSupport (a private Framework) and add the entitlement (also reserved): if you do any of these your app will be refused. – Zmaster Feb 13 '15 at 19:56
  • No, I am actually just thinking about getting this to work on my personal phone, i.e. uploading it from xcode onto my iphone. I have given up on hoping to become rich by selling apps through the app store but am not ready yet to jail broke my brand new iphone just to see if I can get this to work. – Lolo Feb 14 '15 at 02:08
  • @Lolo, sorry for the delay in responding. No, you can't do this without a jailbroken device. – Nate May 15 '15 at 03:39
3

Add com.apple.SystemConfiguration.SCPreferences-write-access to your entitlements plist and set it to true (you may need to create the plist). I believe the following should work - if it doesn't I can look later tonight when I'm able to test it:

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
jrtc27
  • 8,496
  • 3
  • 36
  • 68
  • 1
    "com.apple.SystemConfiguration.SCPreferences-write-access" entitlement is beyond private API. It's only available on jailbroken devices. – Victor Ronin Nov 15 '12 at 16:23