简体   繁体   中英

UIDeviceListener not working in iOS 10

I am using UIDeviceListener-master ( https://github.com/eldade/UIDeviceListener ) class for fetching batteryCount, batterymaximumCapacity but its listner class never gets called.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listenerDataUpdated:) name: kUIDeviceListenerNewDataNotification object:nil];

Please provide me solution for fetching battery details in iOS10.

It's not working on iOS10, you can find more information on UIDeviceListener Github issues https://github.com/eldade/UIDeviceListener/issues/3

You can use 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM