簡體   English   中英

如何使用私有API在IOS 5.1中打開/關閉飛行模式

[英]How to turn on/off airplane mode in IOS 5.1 using private API

我正在嘗試使用私有框架在IOS 5.1中打開/關閉飛行模式。

在AppSupport.framework中, RadiosPreferences具有獲取/設置飛行模式並設置值的屬性

./AppSupport.framework/RadiosPreferences.h

@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是實際存儲飛行模式首選項的文件,因此您需要寫入訪問權限。

,您不需要使用dlopendlsym來訪問此API。 您可以AppSupport框架直接(與例外添加到您的項目AppSupport.framework是根據存儲在您的Mac上PrivateFrameworks文件夾)。 然后,只需實例化RadiosPreferences對象,並正常使用它。 權利是重要的部分。

對於您的代碼,首先使用class-dumpclass-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

這是Saurik關於代碼簽名和權利的頁面

添加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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM