[英]IOS Notification when charging
例如,可以从应用程序获取通知:
然后可以从该通知中采取措施吗?
而且,最后一个:即使我的应用未运行,也可能会收到此通知吗? 就像我收到Whatsapp消息时收到推送通知一样?
谢谢你的帮助 !
您可以使用Apple的此代码监视电池的电量和状态。
float batteryLevel = [UIDevice currentDevice].batteryLevel; //gets the battery's level
UIDeviceBatteryState currentState = [UIDevice currentDevice].batteryState; //gets the battery's status
// Register for battery level and state change notifications.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryLevelChanged:)
name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryStateChanged:)
name:UIDeviceBatteryStateDidChangeNotification object:nil];
您可以使用这些通知来触发所需的任何事件(例如本地通知)。
但是,如果您的应用未运行(在前台或后台),您将无法监视任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.