简体   繁体   English

充电时的iOS通知

[英]IOS Notification when charging

is possible to get notifications from an App when for exemple : 例如,可以从应用程序获取通知:

  • I plug the charger? 我插入充电器了吗?
  • I am at 100% of charge? 我是100%收费的吗?

Is it possible then to get an action to be done from this notification ? 然后可以从该通知中采取措施吗?

And, last one : is it possible to have this notification even if my app is not running ? 而且,最后一个:即使我的应用未运行,也可能会收到此通知吗? Just like I receive push notification when I get a Whatsapp message ? 就像我收到Whatsapp消息时收到推送通知一样?

thanks for your help ! 谢谢你的帮助 !

You can monitor the battery's level and status with this code from Apple . 您可以使用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];

You can use those notifications to trigger whatever event you want (like local notifications). 您可以使用这些通知来触发所需的任何事件(例如本地通知)。
However, you won't be able to monitor anything if your app is not running (either in the foreground or the background). 但是,如果您的应用未运行(在前台或后台),您将无法监视任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM