ios - 如何在应用程序未运行时安排某些事件的本地通知?

标签 ios notifications background-process

我只是尝试创建 UILocalNotification,安排它,然后关闭应用程序并等待通知出现。它工作得很好,因为我在创建通知后的 10 秒内定义了触发时间。

但是如何安排本地通知,或者在例如充电器插入设备时执行一些代码?可能吗?当应用程序未运行但应用程序知道我注册要观察的更改时,我可以执行更改吗?

换句话说,每次插入/拔出充电器时,我都需要安排本地通知。无论应用程序是否正在运行。

最佳答案

您可以在 iOS 中获取充电器插入状态,

UIDeviceBatteryState batteryState = [UIDevice currentDevice].batteryState;
if (currentState == UIDeviceBatteryStateCharging || currentState == 
UIDeviceBatteryStateFull) {
// The battery is either charging, or connected to a charger and is fully charged

But you cannot reschedule notification even app is not running.

关于ios - 如何在应用程序未运行时安排某些事件的本地通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41439954/

相关文章:

linux - 如何将进程置于 Chef 的后台,类似于来自终端的 Ctrl + Z

ios - CCBlade 不适用于 cocos2d-x 3.8 版本

PHP通知

iphone - 调用addObserver和removeObserver方法的可能位置

swift - 来自 notification.userInfo 的数据

ios - 应用程序更新后是否可以恢复 centralManager 状态?

ruby-on-rails-3 - Rails 3 delay_job "TypeError: can' t 转储匿名模块"

ios - 无法以沙盒用户身份购买 IAP

ios - TextEditor 在 SwiftUI 中被键盘遮挡

ios - 如何将自定义 HTTP header 添加到 AVAssetResourceLoaderDelegate 加载请求中