sonido recuperar porque por equipo encuentra eliminado dispositivos dispositivo configurar conectar como iphone

iphone - recuperar - Detectar si el dispositivo se está cargando



configurar bluetooth iphone 6 (5)

Puede usar el centro de notificación de darwin y usar el nombre del evento com.apple.springboard.fullycharged .

De esta manera, recibirá una notificación de su método personalizado, aquí hay un recorte de código:

// Registering for a specific notification NSString *notificationName = @"com.apple.springboard.fullycharged"; CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, yourCustomMethod, (__bridge CFStringRef)notificationName, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

// The custom method that will receive the notification static void yourCustomMethod(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { NSString *nameOfNotification = (__bridge NSString*)name; if([nameOfNotification isEqualToString:notificationName]) { // Do whatever you want... } }

No puedo encontrar nada definido usando mi herramienta favorita , sin embargo, pensé que lo pondría aquí ...

¿Hay alguna forma, utilizando el iPhone SDK, para que una aplicación detecte si el dispositivo se encuentra en un estado de alimentación (carga, acoplamiento, etc.)?

Me gustaría poder deshabilitar el idleTimer automáticamente si el dispositivo está recibiendo alimentación (de lo contrario es una configuración especificada por el usuario).


Sí, UIDevice es capaz de decirte esto:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) { NSLog(@"Device is charging."); }

Consulte la referencia de UIDevice en los documentos para obtener más información y para otros valores de batteryState.


Swift 3:

UIDevice.current.isBatteryMonitoringEnabled = true let state = UIDevice.current.batteryState if state == .charging || state == .full { print("Device plugged in.") }


Usted está mejor usando:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) { [UIApplication sharedApplication].idleTimerDisabled=YES; }

Esto se debe a que debe preocuparse por dos estados diferentes: uno es que la batería se está cargando y el otro cuando está completamente cargada .

Si realmente deseaba completarlo, se registraría para recibir notificaciones de monitoreo de la batería, por lo que podría volver a habilitar el temporizador de inactividad si el usuario desconecta la alimentación principal, etc.


Swift 4

UIDevice.current.isBatteryMonitoringEnabled = true if (UIDevice.current.batteryState != .unplugged) { print("Device is charging.") }

Swift 3

UIDevice.currentDevice().batteryMonitoringEnabled = true; if (UIDevice.currentDevice().batteryState != .Unplugged) { print("Device is charging."); }