我只是尝试创建 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/