OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在应用程序未运行时安排某些事件的本地通知? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:29
标题: ios - 如何在应用程序未运行时安排某些事件的本地通知?

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

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

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



Best Answer-推荐答案


你可以在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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4