LoginSignup
49
48

More than 5 years have passed since last update.

節電モードを検出してお行儀の良いアプリに

Posted at

省電力モード?

iOS9はバッテリーが少ない時にLow Power Mode(低消費電力モード)へ切り替わるようになっており(ユーザー自身が設定することもできます)、設定すると省エネ対策(通信頻度やアニメーションなどなど)が働きバッテリーの寿命を節約します。

低消費電力モードの取得

現在省電力モードか判定する実装です。

  • Objective-C
if ([[NSProcessInfo processInfo] isLowPowerModeEnabled]) {
    // Low Power Mode is enabled. Start reducing activity to conserve energy.
} else {
    // Low Power Mode is not enabled.
};
  • Swift
if NSProcessInfo.processInfo().lowPowerModeEnabled {
    // Low Power Mode is enabled. Start reducing activity to conserve energy.
} else {
    // Low Power Mode is not enabled.
}

低消費電力モード変更の取得

電力モードが変更された通知を受け取るための実装です。

  • Objective-C
[NSNotificationCenter defaultCenter] addObserver:self
   selector: @selector(yourMethodName:)
   name: NSProcessInfoPowerStateDidChangeNotification
   object: nil];
  • Swift
NSNotificationCenter.defaultCenter().addObserver(
    self,
    selector: “yourMethodName:”,
    name: NSProcessInfoPowerStateDidChangeNotification,
    object: nil
)

注意

状態が不明だったり、デバイスが低電力モードをサポートしていない場合は常にNO(false)となります。

まとめ

省電力モードの際は、位置情報の取得頻度や通信頻度やアニメーションを減らし、バッテリーの節約を行うことでユーザーにとって嬉しいお行儀の良いアプリにしていきましょう。

参考

49
48
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
49
48