如何使用私有API在IOS 5.1中打开/closures飞行模式

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

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

./AppSupport.framework/RadiosPreferences.h

 @property BOOL airplaneMode; 

./AppSupport.framework/RadiosPreferences.h

 - (void)setAirplaneMode:(BOOL)arg1; 

我怎样才能使用这些方法? 我是否需要使用dlsym创build一个对象并调用这些方法? 有人可以帮助我的示例代码或方法来做到这一点。

正如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上的AppSupport.framework文件夹中除外)。 然后,实例化一个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 

我只testing过这个越狱应用程序。 如果设备没有越狱,我不确定是否有可能获得这个权利(参见Victor Ronin的评论)。 但是,如果这是一个越狱应用程序,请确保您记得使用授权文件签署您的可执行文件。 我通常使用ldid签署越狱应用程序,所以如果我的权利文件是entitlements.xml ,那么在Xcode中编译而没有代码签名之后 ,我会执行

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

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

添加com.apple.SystemConfiguration.SCPreferences-write-access权限plist并将其设置为true(您可能需要创buildplist)。 我相信以下几点应该是有效的 – 如果不行的话,我可以在今天晚些时候看看,

 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