Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
私有iOS框架返回NULL_Ios_Iphone Privateapi - Fatal编程技术网

私有iOS框架返回NULL

私有iOS框架返回NULL,ios,iphone-privateapi,Ios,Iphone Privateapi,我正试图在iOS 9.1的帮助下使用BatteryCenter和CommonUtilities私有框架。这是出于研究目的,不会进入应用商店 以下是它们各自的代码: - (void)batteryCenter { NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/BatteryCenter.framework"]; BOOL success = [bundle load]; if

我正试图在iOS 9.1的帮助下使用
BatteryCenter
CommonUtilities
私有框架。这是出于研究目的,不会进入应用商店

以下是它们各自的代码:

- (void)batteryCenter {
NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/BatteryCenter.framework"];
BOOL success = [bundle load];

    if(success) {
        Class BCBatteryDevice = NSClassFromString(@"BCBatteryDevice");
        id si = [[BCBatteryDevice alloc] init];

        NSLog(@"Charging: %@", [si valueForKey:@"charging"]);
    }
}


- (void)commonUtilities {
    NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/CommonUtilities.framework"];
    BOOL success = [bundle load];

    if(success) {
        Class CommonUtilities = NSClassFromString(@"CUTWiFiManager");
        id si = [CommonUtilities valueForKey:@"sharedInstance"];

        NSLog(@"Is Wi-Fi Enabled: %@", [si valueForKey:@"isWiFiEnabled"]);
        NSLog(@"Wi-Fi Scaled RSSI: %@", [si valueForKey:@"wiFiScaledRSSI"]);
        NSLog(@"Wi-Fi Scaled RSSI: %@", [si valueForKey:@"lastWiFiPowerInfo"]);
    }
}
虽然我得到了这些类,但它们所有的值都是空的,这很奇怪,因为有些值必须是真的,例如,我连接到了Wi-Fi,所以
isWiFiEnabled
应该是
YES


我的代码没有返回预期的结果,到底缺少了什么?它需要权利吗?如果是,具体是什么?

在执行成功块后,您需要首先访问
BCBatteryDeviceController
,通过它可以获得所有连接设备的列表

下面是相同的代码

Class CommonUtilities = NSClassFromString(@"BCBatteryDeviceController");

id si = [CommonUtilities valueForKey:@"sharedInstance"];

BCBatteryDeviceController* objBCBatteryDeviceController = si;

NSLog(@"Connected devices: %@", objBCBatteryDeviceController.connectedDevices);

在Swift中,我在没有
BatteryCenter
标题的情况下成功地实现了这一点。我仍在寻找一种不使用
bcbatterydeviconroller
访问已连接电池列表的方法,但这就是我目前所做的工作:

Swift 3:

guard case let batteryCenterHandle = dlopen("/System/Library/PrivateFrameworks/BatteryCenter.framework/BatteryCenter", RTLD_LAZY), batteryCenterHandle != nil else {
    fatalError("BatteryCenter not found")
}

guard let batteryDeviceControllerClass = NSClassFromString("BCBatteryDeviceController") as? NSObjectProtocol else {
    fatalError("BCBatteryDeviceController not found")
}

let instance = batteryDeviceControllerClass.perform(Selector(("sharedInstance"))).takeUnretainedValue()

if let devices = instance.value(forKey: "connectedDevices") as? [AnyObject] {

    // You will have more than one battery in connectedDevices if your device is using a Smart Case
    for battery in devices {
        print(battery)
    }
}
Swift 2.2:

guard case let batteryCenterHandle = dlopen("/System/Library/PrivateFrameworks/BatteryCenter.framework/BatteryCenter", RTLD_LAZY) where batteryCenterHandle != nil else {
    fatalError("BatteryCenter not found")
}

guard let c = NSClassFromString("BCBatteryDeviceController") as? NSObjectProtocol else {
    fatalError("BCBatteryDeviceController not found")
}

let instance = c.performSelector("sharedInstance").takeUnretainedValue()
if let devices = instance.valueForKey("connectedDevices") as? [AnyObject] {

    // You will have more than one battery in connectedDevices if your device is using a Smart Case
    for battery in devices {
        print(battery)
    }
}
此日志记录:

<BCBatteryDevice: 0x15764a3d0; vendor = Apple; productIdentifier = 0; parts = (null); matchIdentifier = (null); baseIdentifier = InternalBattery-0; name = iPhone; percentCharge = 63; lowBattery = NO; connected = YES; charging = YES; internal = YES; powerSource = YES; poweredSoureState = AC Power; transportType = 1 >