充电时的IOS通知

标签 ios background notifications apple-push-notifications

例如,可以从应用程序获取通知:

  • 我插上充电器?
  • 我的电量是 100%?

是否有可能从此通知中获得要完成的操作?

还有,最后一个:即使我的应用程序没有运行,是否也可以收到此通知?就像我收到 Whatsapp 消息时收到推送通知一样?

感谢您的帮助!

最佳答案

您可以使用 this code from 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];

您可以使用这些通知来触发您想要的任何事件(例如本地通知)。
但是,如果您的应用未运行(无论是在前台还是在后台),您将无法监控任何内容。

关于充电时的IOS通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33169880/

相关文章:

CSS 包装器背景未出现

ios - 是否可以从应用程序本身访问应用程序的推送通知状态?

ios - 在 ios 中使用 StoryBoard 的一个按钮和多个操作

Java 更改按钮背景颜色

ios - 如何将 json 响应存储到变量中?

javascript - javascript 中的背景位置不起作用

c# - 如何从桌面应用程序中的 Windows Toast 通知接收文本框值?

javascript - 通知 - 替代 Object.observe?

ios - 日期格式化程序 - 截至日期的字符串 2012-02-05T00 :00:00+00:00

ios - 自定义 UIView 使用 init(coder) 初始化,如何使用 init(frame) 初始化它