【问题标题】:Private iOS Framework Returning NULL私有 iOS 框架返回 NULL
【发布时间】:2023-03-09 00:20:02
【问题描述】:

我正在尝试在nst's iOS Runtime Headers 的帮助下在iOS 9.1 下使用BatteryCenterCommonUtilities 私有框架。它用于研究目的,不会上架 AppStore。

这是他们各自的代码:

- (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"]);
    }
}

虽然我找回了类,但它们所有受尊重的值都是 NULL,这很奇怪,因为有些必须是真的,例如我已连接到 Wi-Fi,所以 isWiFiEnabled 应该是 YES

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

【问题讨论】:

    标签: ios iphone-privateapi


    【解决方案1】:

    在 Swift 中,我设法在没有 BatteryCenter 标头的情况下使其工作。我仍在寻找一种不使用BCBatteryDeviceController 来访问附加电池列表的方法,但这是我迄今为止所做的工作:

    斯威夫特 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)
        }
    }
    

    斯威夫特 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 >
    

    【讨论】:

      【解决方案2】:

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

      这是相同的代码。

      Class CommonUtilities = NSClassFromString(@"BCBatteryDeviceController");
      
      id si = [CommonUtilities valueForKey:@"sharedInstance"];
      
      BCBatteryDeviceController* objBCBatteryDeviceController = si;
      
      NSLog(@"Connected devices: %@", objBCBatteryDeviceController.connectedDevices);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-23
        • 2017-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-26
        相关资源
        最近更新 更多