1

I'm a beginner to iOS, and want to see if I can have an app note the time that the phone's screen turns on or off. This would basically always be running in the background. I've read a lot of solutions that will work for jailbroken iPhones, or use launch daemons that seem to not be accepted in the Apple Store. Is there any way to gather that info that Apple may be okay with?

The closest thing I've seen seems to be the protectedDataAvailable property as a flag for if the screen is on or off, but I'm not sure how I could run this continuously in the background and save any time data.

Any help is appreciated, thanks so much!

mcw
  • 465
  • 1
  • 4
  • 14

1 Answers1

1

Not really. There are restrictions which app can run in the background, I think it's only allowed for voip apps, messengers and music players. All other apps can continue to run tasks in the background but get killed after 10 minutes if the task is not finished until then.

The available background modes for store apps: (Look for UIBackgroundModes)

https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW22

the app reviewer will check if your app fit's in the chosen category.

Bastian
  • 10,403
  • 1
  • 31
  • 40
  • Thanks for the answer. Do you happen to know how strict it is? For example if I had a location feature that didn't necessarily do anything, just to keep it running in the background, would that work? Or are they looking at both what it does and how it does it? – mcw Jun 25 '14 at 07:49
  • Location services won't help you. Enabling this mode does not prevent the system from suspending the app, but it does tell the system that it should wake up the app whenever there is new location data to deliver. The user will asked if your app is allowed to track location and it won't work if the user denies it. – Bastian Jun 25 '14 at 08:30
  • Also they check if you just try to circumvent the background restrictions... if they think you do they won't let you. – Bastian Jun 25 '14 at 08:33
  • So my "beacon of light" so to speak was that apps that collect data usage and show you how much data you are using on wifi/cellular networks would need a similar kind of background action. How do those work? – mcw Jun 25 '14 at 17:09
  • there are counters for that from last boot.. no need to run in background: http://stackoverflow.com/questions/7946699/iphone-data-usage-tracking-monitoring – Bastian Jun 27 '14 at 08:14