Sempre [myDevice batteryLevel]
restituendo -1 e [myDevice batterystate]
restituendo 0 (inserendo nel caso Predefinito).Come ottenere il corretto livello della batteria e lo stato della batteria-ios?
Come posso ottenere i valori corretti? .Come chiunque mi aiuti a risolvere questo? .Below è il mio codice. (Stampa sempre BatteryLeft come "-100%" e Stato batteria come "Sconosciuto").
Codice:
UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel]*100;
int status=[myDevice batteryState];
NSLog(@"level:%0.0f",batLeft);
NSString *status_str;
switch (status)
{
case UIDeviceBatteryStateUnplugged:
{
NSLog(@"UnpluggedKey");
[email protected]"UnPlugged";
break;
}
case UIDeviceBatteryStateCharging:
{
NSLog(@"ChargingKey");
[email protected]"Charging";
break;
}
case UIDeviceBatteryStateFull:
{
NSLog(@"FullKey");
[email protected]"BatteryFul";
break;
}
default:
{
NSLog(@"UnknownKey");
[email protected]"Unknown";
break;
}
}
NSLog(@"Battery status:%@",status_str);
Stai test su dispositivo o simulatore? test sul simulatore ti darà l'output che stai ottenendo ora. :-) –