0

I am downloading the data at background from server in an offline app, where the data will be downloaded when the app launches for the first time .Later the app will be used as offline app.

I need to place the condition to check whether the data couldn't be downloaded due to low battery, Network issues etc.

Where Can I handle these in app life cycle?

soumya
  • 3,801
  • 9
  • 35
  • 69
  • show some code how you are doing the download, what API's are you using? your best bet will probably be in the appDelegates `applicationDidEnterBackground` and `applicationWillTerminate` – Fonix Nov 14 '14 at 07:40

1 Answers1

0

You can check [[UIDevice currentDevice] batteryState] if device is charging

UIDeviceBatteryStateUnknown,
UIDeviceBatteryStateUnplugged,   // on battery, discharging
UIDeviceBatteryStateCharging,    // plugged in, less than 100%
UIDeviceBatteryStateFull,        // plugged in, at 100%

Also you can get battery level via [[UIDevice currentDevice] batteryLevel] and decide to download content or not.

Note that batteryLevel is not so accurate, it rounded to 0.5
If you need more accurate measurements have a look https://github.com/nst/BatteryChart

l0gg3r
  • 8,864
  • 3
  • 26
  • 46