检测低电量警告ios [英] Detect low battery warning ios

查看:134
本文介绍了检测低电量警告ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个基于回合的游戏。为了防止用户作弊,如果用户在转弯中间关闭应用程序,转弯将自动传递给对手。这是因为用户无法关闭应用程序,重新启动它,并从头开始转弯。

I'm making a turnbased game. To prevent users from cheat, the turn will automatically get passed to the opponent if the user close the app in the middle of a turn. This because so the user can't close the app, restart it, and beging the turn from the beginning.

但有两种情况会对玩家造成不利影响。如果有电话呼入,或出现电池电量不足警告。我可以检测到来电并回复,但我不知道该如何处理电池?

There are two cases that should penalize the player however. If a phone call gets in, or the low battery warning appears. I can detect the phone call coming in and respond, but I don't know what to do with the battery?

任何建议都很棒

推荐答案

通过将 UIDevice 单身的属性设置为YES来启用电池监控:

Battery monitoring is enabled by setting to YES a property of the UIDevice singleton:

UIDevice *device = [UIDevice currentDevice];
device.batteryMonitoringEnabled = YES;

iPhone OS 提供两种类型的电池监控事件,一个用于状态改变时(例如,充电,未插电,完全充电)和一个在电池电量变化时更新的事件。与接近监控的情况一样,您注册回调以接收通知:

iPhone OS provides two type of battery monitoring events, one for when the state changes (e.g., charging, unplugged, full charged) and one that updates when the battery’s charge level changes. As was the case with proximity monitoring, you register callbacks to receive notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryLevelDidChangeNotification" object:device];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryStateDidChangeNotification" object:device];

还可以参考链接。

这篇关于检测低电量警告ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆