我正在使用UIDeviceListener-master(https://github.com/eldade/UIDeviceListener)类来获取batteryCount,batterymaximumCapacity,但它的listner类永远不会被调用。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listenerDataUpdated:) name: kUIDeviceListenerNewDataNotification object:nil];
请向我提供在iOS10中获取电池详细信息的解决方案。
答案 0 :(得分:0)
它不能在iOS10上运行,你可以找到有关UIDeviceListener Github问题的更多信息https://github.com/eldade/UIDeviceListener/issues/3
您可以使用IOKit:
mach_port_t iokitPort = 0;
CFMutableDictionaryRef properties;
IOMasterPort(0, &iokitPort);
CFDictionaryRef serviceName = IOServiceNameMatching("AppleARMPMUCharger");
io_service_t service = IOServiceGetMatchingService(iokitPort, serviceName);
if (service == 0)
return nil;
kern_return_t status = IORegistryEntryCreateCFProperties(service,
&properties,
kCFAllocatorDefault,
kNilOptions);
IOObjectRelease(service);