I want to execute some code when iPhone battery iPhone run out of battery.
Will func applicationWillTerminate(_ application: UIApplication) {
be called? If no then does exist any other way to track this? Thanks in advance.
There is no support for this instead you have to decide when the battery level is so low that you need to run your code.
What you can do is listen to the notification batteryLevelDidChangeNotification
which is done by activating monitoring see isBatteryMonitoringEnabled
Like mentioned in the documentation the notifications are sent no more than once per minute so you have to determine a battery level that is low enough to be considered as almost depleted and then execute the code.
I have no idea what this could be, from personal experience I have seen my phones stay alive a long time on values under 5% but also seen them die shortly after going below 10%