Как получить уровень заряда батареи от IOKit в iOS 3 SDK, используя theos?

Итак, я хочу использовать IOKit, чтобы показать уровень заряда батареи в процентах для iOS 3 SDK с использованием theos, и он компилируется правильно, но когда он пытается связать некоторые символы, он говорит:

 Linking Application Battery...
Undefined symbols:
 "IOPSCopyPowerSourcesList(void const*)", referenced from:
   -[RootViewController IOKitBatteryLevel] in RootViewController.mm.8c9b32f3.o
 "IOPSCopyPowerSourcesInfo()", referenced from:
   -[RootViewController IOKitBatteryLevel] in RootViewController.mm.8c9b32f3.o
 "IOPSGetPowerSourceDescription(void const*, void const*)", referenced from:
   -[RootViewController IOKitBatteryLevel] in RootViewController.mm.8c9b32f3.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [obj/Battery.app/Battery.64873355.unsigned] Error 1
make[1]: *** [internal-application-all_] Error 2
make: *** [Battery.all.application.variables] Error 2

Мой.h для RootViewController это:

@interface RootViewController: UIViewController {
// some irrelevant declarations
float level;
float percent;
}

@end

И мой.mm для RootViewController это:

#import "RootViewController.h"
#include "IOPowerSources.h"
#include "IOPSKeys.h"
#import <IOKit/IOKit.h>
#import <IOKit/IOKitLib.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CFDictionary.h>

@implementation RootViewController

- (double)IOKitBatteryLevel {
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
CFArrayRef sources = IOPSCopyPowerSourcesList(blob);

CFDictionaryRef pSource = NULL;
const void *psValue;

int numOfSources = CFArrayGetCount(sources);
if (numOfSources == 0) {
    NSLog(@"-- No power source found");
    return -1.0f;
}

for (int i = 0 ; i < numOfSources ; i++)
{
    pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
    if (!pSource) {
        NSLog(@"-- Can't get power source description");
        return -1.0f;
    }
    psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));

    int curCapacity = 0;
    int maxCapacity = 0;

    psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSCurrentCapacityKey));
    CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &curCapacity);

    psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSMaxCapacityKey));
    CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &maxCapacity);
    percent = (float)((double)curCapacity/(double)maxCapacity * 100.0f);
    return ((double)curCapacity/(double)maxCapacity * 100.0f);
}
return percent;
}

- (void)loadView {
// some code I will not share

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryStatusDidChange:) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
// some more code I will not share
level = [self IOKitBatteryLevel];
// even more code I will not share
progress.progress = level;
// some code after that
}

- (void)batteryStatusDidChange:(NSNotification *)notification {
level = [self IOKitBatteryLevel];
}

@end

Имейте в виду, что это правильно компилируется с iOS 3 SDK на моем iPod Touch 2G (iOS 4.2.1), просто не будет связывать приложение.

0 ответов

Другие вопросы по тегам