Well thanks, but it's a bit more convoluted than that.
He obviously does not want to switch the auto-lock completely off; that would clash seriously with the normal usage, when the iPhone is not charging (or he would have to remember to switch is always back on whenever he takes the iPhone from the dock, which is self-evidently absurd).
The good news is that this is actually not needed at all! Once my application is active, it can both monitor the charging status (through the batteryState property) and, if the iPhone is being charged, it can easily keep the screen unlocked through idleTimerDisabled.
The bad news is that to be able to do this, the app needs to be active. That's why I need a way to automatically launch/activate the application when the device is put into the charger — that's one thing whole solution I can't see :/
(The other one is to make the app automatically launched/activated if the charging is in process, another app is active, and the idle timer strikes in: normally iPhone would switch off the display in this case, I need it again to activate my app.)
Unless I am missing something of importance, that's all I need; all the other requirements I do know how to implement easily.
So, if I understand, you want to use some notification of charge to launch/activate your app ?
Do you want to launch the app or only to activate from background ?
As far as I understand, the first is not possible:
For the second, you could detect that the iPhone has been plugged / unplugged
Hope that can be of some help.
> you want to use some notification of charge to launch/activate your app?
Essentially, yes. More precisely, I need the app to be launched/activated somehow when charging begins; I do not really care whether the mechanism used for that is a notification or anything else.
> Do you want to launch the app or only to activate from background?
Well as “launch/activate” sort of suggest, I would need it to be activated if it happens to be suspended (or runs, which it very probably would not, see below) at bacground; launched if it does not run at all.
> As far as I understand, the first is not possible
Actually, a local notification (alerting the user who would tap the alert to launch the app) would be quite an acceptable solution — provided that notification could come exactly at (or very shortly after, let's say up to a second or two at very worst) the moment when the device starts charging.
Is that possible? As always, I can be missing something of importance, but I don't know such a local notification can be requested. Is there a way to do that? All I know are time- and location-based local notifications, none of which helps here the slightest bit.
> For the second, you could detect that the iPhone has been plugged / unplugged
Absolutely, provided my application actually runs at background, which is generally — again, far as I understand — not possible to achieve.
Again do please correct me if I am wrong, but far as I know, Apple does not allow applications to run at background, unless they play a (silent, in this case) audio, which is trick dirty enough for my client to frown upon, not speaking of the Store, which well might reject such a thing. There's also BGTaskScheduler now, but it won't make sure my app gets a few ticks of CPU at least each second, which is roughly what I would need; the new API, far as I understand the thing, might well leave the app dormant for minutes (or hours or days)
If there's any other possibility to make my app really run at bacground (well, aside of VoIP which is not a solution for roughly same reasons as the audio-play hack) — or, even better, be reliably resumed at background each second or so —, I never heard of the thing, and would be grateful if you point it to me.
Thanks and all the best,
AFAIK, You can receive notification when in background, but nore sure timing is guaranteed.
I guess you've read this doc already:
This may help: