iPhone "background activity" when the screen is locked

1,447 views
Skip to first unread message

mobweb

unread,
Jan 27, 2010, 7:23:21 AM1/27/10
to phonegap
Hello fellow phonegappers,

Does anyone know where the behavior of the iPhone/phonegap in the
locked state is documented? I mean the state when the user either
locks the screen by pressing the lock button or when he doesn't touch
the screen for a minute (or whatever is set in the settings).

The reason why I'm interested in that is because I've been coding an
app that has an "alarm" feature. As far as I understand, it is not
possible to fire an alert or do anything at all once the screen has
been locked. What would be perfect for my app is if this scenario
worked:

The user sets an "alarm time" of let's say 30 minutes, and then he
places his phone somewhere and doesn't touch it for 30 minutes. After
the 30 minutes, the phone plays an alarm file.

Unfortunately I have thus far only been able to fire the alarm if the
phone is set not to go into the lock state (which is bad for the
screen I suppose).

Any help is much appreciated.

Best regards

Todd Blanchard

unread,
Jan 27, 2010, 2:22:23 PM1/27/10
to mobweb, phonegap
Most likely, the best solution is to send the alarm definition to a web server that can then issue a push notification at the specified time.

OTOH, I don't know if phonegap apps can accept push notifications since I just now signed up and started playing with it.

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

mobweb

unread,
Jan 28, 2010, 10:01:24 AM1/28/10
to phonegap
Nevermind, I found the solution (or workaround, really) with some
googling.

It's possible to disable the auto lock/dim using some Objective C.

All you have to do is change phonegapdelegate.m:

Right after:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{

You have to add:

[UIApplication sharedApplication].idleTimerDisabled = YES;

And it won't lock. :D

Kerri Shotts

unread,
Aug 20, 2012, 7:30:34 PM8/20/12
to phon...@googlegroups.com, phon...@googlegroups.com
AFAIK, you can't make that determination. When locked, iOS is free to send your app to the background, just like it does with the Home button. Likewise, it is free at a later point in time to terminate the app (however, this would be rare: there's not usually a lot else going on while locked: just checking email, receiving notifications, etc., and those wouldn't normally nuke the foreground app).

If an app doesn't supports multitasking without audio/networking/gps, it will be totally backgrounded by iOS when locked (or via the home button). It's not so much a matter of the app detecting a keypress -- the state is managed by the OS before you even get the chance to look at keycodes. If your app needs audio/network/gps, iOS can keep the app alive (perhaps for only a few minutes, in the case of networking), but in this case, your app wouldn't know the screen was locked.

Now I'm certain there /are/ ways to figure all this out via private/undocumented APIs. But Apple won't let those in to the store, so it's not worth going there. 

So, to the best of my knowledge, this isn't possible. Perhaps it would be a good idea to explain what operations you would like to have happen in each scenario? Perhaps there are better ways to accomplish what you want.

______________________________
Kerri Shotts
photoKandy Studios LLC

📱 Phone: +1 (312) 380-1035
🌐 Web: http://photokandy.com 

Twitter: @photokandy


On Aug 20, 2012, at 11:28, German Larrosa <german....@gmail.com> wrote:

Hi,

I am developing a cross mobile application that runs over iOS and Android.

So, I wanted to be attached to the power button in order to make some proccessing whenever a user presses the power button, and also I need to do some different proccesing when home button is pressed so I need I way to discriminate when home button was pressed and when lock/power button was pressed.

I was looking at phongegap docs without success so I found a way to solve that using native Android code but I couldnt find a way to do that on iOS. 

Therefore if anyone knows any way to accomplish that using native iOS code just let me know!

Thanks!

German L.

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 
Reply all
Reply to author
Forward
0 new messages