❄️
[iOS JB] Private APIで、Wi-Fi, Bluetooth, Airplane, Cellularのオンオフを切り替える
Wi-Fi
entitlements.plist # 追記
<key>com.apple.wifi.manager-access</key>
<true/>
Makefile # 追記
$(APP_NAME)_FRAMEWORKS += MobileWiFi
main.m
#if __cplusplus
extern "C" {
#endif
typedef struct __WiFiManager *WiFiManagerRef;
WiFiManagerRef WiFiManagerClientCreate(CFAllocatorRef allocator, int flags);
void WiFiManagerClientSetProperty(WiFiManagerRef manager, CFStringRef property, CFPropertyListRef value);
#if __cplusplus
}
#endif
void setWiFiMode(BOOL mode) {
void* manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
CFBooleanRef value = (mode ? kCFBooleanTrue : kCFBooleanFalse);
WiFiManagerClientSetProperty(manager, CFSTR("AllowEnable"), value);
CFRelease(manager);
}
BOOL getWiFiMode() {
return [[[[NSDictionary alloc] initWithContentsOfFile:@"/var/preferences/SystemConfiguration/com.apple.wifi.plist"] objectForKey:@"AllowEnable"] boolValue];
}
// SSIDを取得する (Aterm-410051025 etc...)
#if __cplusplus
extern "C" {
#endif
typedef struct __WiFiManager *WiFiManagerRef;
typedef struct __WiFiNetwork *WiFiNetworkRef;
typedef struct __WiFiDeviceClient *WiFiDeviceClientRef;
WiFiManagerRef WiFiManagerClientCreate(CFAllocatorRef allocator, int flags);
void WiFiManagerClientSetProperty(WiFiManagerRef manager, CFStringRef property, CFPropertyListRef value);
WiFiNetworkRef WiFiDeviceClientCopyCurrentNetwork(WiFiDeviceClientRef client);
CFStringRef WiFiNetworkGetSSID(WiFiNetworkRef network);
CFArrayRef WiFiManagerClientCopyDevices(WiFiManagerRef manager);
#if __cplusplus
}
#endif
NSString *getWiFiSSID() {
WiFiManagerRef manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
CFArrayRef devices = WiFiManagerClientCopyDevices(manager);
WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);
WiFiNetworkRef network = WiFiDeviceClientCopyCurrentNetwork(client);
return CFBridgingRelease(WiFiNetworkGetSSID(network));
}
https://github.com/davidmurray/ios-reversed-headers/blob/master/MobileWiFi/WiFiManager.h
Bluetooth
entitlements.plist # 追記
<key>com.apple.bluetooth.system</key>
<true/>
main.m
#import <BluetoothManager/BluetoothManager.h>
void setBluetoothMode(BOOL mode) {
BluetoothManager *manager = [objc_getClass("BluetoothManager") sharedInstance];
[manager setEnabled:mode];
[manager setPowered:mode];
}
BOOL getBluetoothMode() {
BluetoothManager *manager = [objc_getClass("BluetoothManager") sharedInstance];
return [manager powered] && [manager enabled];
}
機内モード (AirplaneMode)
entitlements.plist # 追記
<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>
Makefile # 追記
$(APP_NAME)_PRIVATE_FRAMEWORKS += AppSupport
main.m
@interface RadiosPreferences : NSObject
- (bool)airplaneMode;
- (void)setAirplaneMode:(bool)arg1;
@end
void setAirplaneMode(BOOL mode) {
RadiosPreferences *radiosPreferences = [[RadiosPreferences alloc] init];
[radiosPreferences setAirplaneMode:mode];
}
BOOL getAirplaneMode() {
RadiosPreferences *radiosPreferences = [[RadiosPreferences alloc] init];
return [radiosPreferences airplaneMode];
}
モバイルデータ (CellularMode)
entitlements.plist # 追記
<key>com.apple.CommCenter.fine-grained</key>
<array>
<string>spi</string>
</array>
Makefile # 追記
$(APP_NAME)_FRAMEWORKS += CoreTelephony
main.m
#import <CoreTelephony/CTCellularDataPlan.h>
void setCellularMode(BOOL mode) {
CTCellularDataPlanSetIsEnabled(mode);
}
BOOL getCellularMode() {
return CTCellularDataPlanGetIsEnabled();
}
// プロバイダー名を取得する (NTT DOCOMO etc...)
#if __cplusplus
extern "C" {
#endif
CFStringRef CTRegistrationCopyLocalizedOperatorName(CFAllocatorRef allocator);
#if __cplusplus
}
#endif
NSString *getCellularName() {
return CFBridgingRelease(CTRegistrationCopyLocalizedOperatorName(NULL));
}
Discussion