例如,可以从应用程序获取通知:
- 我插上充电器?
- 我的电量是 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/