【问题标题】:UIDeviceListener not working in iOS 10UIDeviceListener 在 iOS 10 中不起作用
【发布时间】:2018-01-04 13:20:07
【问题描述】:

我正在使用 UIDeviceListener-master (https://github.com/eldade/UIDeviceListener) 类来获取 batteryCount、batterymaximumCapacity,但它的侦听器类永远不会被调用。

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

请为我提供在 iOS10 中获取电池详细信息的解决方案。

【问题讨论】:

    标签: ios objective-c xcode uidevice


    【解决方案1】:

    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);
    

    【讨论】:

    • 如果我使用 IOKit,app 会在 appstore 中被拒绝??
    • 可能会被拒绝是的
    • 我不想获取电池状态和电池百分比,我只想获取cycleCount
    猜你喜欢
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    相关资源
    最近更新 更多