3

I'm currently writing an iOS application and am receiving battery status change notifications. Of course, when I'm debugging my app it would be nice if I could toggle the battery status without unplugging my phone. Is there any way to do this via OS X or XCode, that is, while having the phone plugged in tell it to stop charging so I can test my notifications and actions?

dgund
  • 3,459
  • 4
  • 39
  • 64
Joe
  • 2,352
  • 20
  • 38

2 Answers2

4

Due to Apple's sandboxing regulations and firmware, you can not tell the phone to stop charging. This is a service extremely close to the core of the phone, and it can not be programmatically accessed.

dgund
  • 3,459
  • 4
  • 39
  • 64
2

Of course, when I'm debugging my app it would be nice if I could toggle the battery status without unplugging my phone.

Since you can't do that (per the accepted answer), an alternative that will help you debug is to create and send your own battery status notifications. The notifications are regular old NSNotification objects, and you can create and send your own with the name set to UIDeviceBatteryLevelDidChangeNotification or UIDeviceBatteryStateDidChangeNotification. That should let you trace through any code that would normally run when your app receives those notifications.

Caleb
  • 124,013
  • 19
  • 183
  • 272