Hello Everyone,
I would like to access some values from a CFMutableDictionaryRef and then do some math on them. Using the code below I have managed to print some properties of my battery. I am also able to print out single values (although in doing so I get a warning:invalid receiver type:CFMutableDictionaryRef).
Then I try to convert the string values to NSNumber and then the program bugs. It gives me something like unrecognized selector sent to instance 0x5d65f70 Any help?
CFMutableDictionaryRef matching , properties = NULL;
io_registry_entry_t entry = 0;
matching = IOServiceMatching( "IOPMPowerSource" );
//matching = IOServiceNameMatching( "AppleSmartBattery" );
entry = IOServiceGetMatchingService( kIOMasterPortDefault , matching );
IORegistryEntryCreateCFProperties( entry , &properties , NULL , 0 );
NSLog( @"%@" , properties );
NSString * voltage = [properties objectForKey:@"Voltage"];
NSString * currentCapacity = [properties objectForKey:@"CurrentCapacity"];
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumber = [f numberFromString:voltage];
[f release];
CFRelease( properties );
IOObjectRelease( entry );