0

Let's say the user leaves the phone on the table. (probably on home screen)

A few hours later, he picks it up. And when it does, the iPhone detects the accelerometer, and it rings.

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

5 Answers5

2

Unfortunately, this is not possible. Once the OS goes to the home screen, applications running in the background have a limited set of options.

Read this article for more information: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

JSager
  • 1,420
  • 9
  • 18
1

Not through officially accepted means (i.e. you could do it on a jailbroken phone conceivably). Primarily, you can't run in the background for that purpose. If the app was running in the foreground, you can easily detect motion and perform an activity - but if the phone is left for too long a period without activity, it will sleep.

rcw3
  • 3,034
  • 1
  • 27
  • 24
1

Unfortunately, the accelerometer is not one of the specified keys in the UIBackgroundModes option in your apps info.plist.

auido, location and voip are the only ones available for now.

dredful
  • 4,378
  • 2
  • 35
  • 54
0

Only if you left an app designed for that purpose running in the foreground.

It won't be possible if your app is running in the background.

Todd Hopkinson
  • 6,803
  • 5
  • 32
  • 34
0

short answer: YES

The trick is to make sure the app doesn't get backgrounded when the phone goes to sleep. The other elements like detecting changes in the accelerometer and playing a sound are all standard features.

As for the no sleep solution, it has been asked before, basically is you play a music sample the app will continue running, so perhaps a loop of silence continuously played.

NWCoder
  • 5,296
  • 1
  • 26
  • 23
  • 1
    If you submit to the store with the little audio trick to stay in background, you not only risk likely rejection from the store, but having your developer account suspended as well. – rcw3 Apr 25 '11 at 17:34
  • Here's a reference if it helps: http://blog.marcopeluso.com/2009/08/23/how-to-prevent-iphone-from-deep-sleeping/ – NWCoder Apr 25 '11 at 17:43
  • A SO question that is related: http://stackoverflow.com/questions/1551712/running-iphone-apps-while-in-sleep-mode – NWCoder Apr 25 '11 at 17:44
  • As far as the app store goes, I think you should make this feature apparent and upfront to the user. I don't believe that you will have your developer account suspended unless you are trying to hide this feature and circumvent standard apple api(s). Which this does not. – NWCoder Apr 25 '11 at 17:45
  • As quoted from the Apple published review quidelines in stack overflow question 3762200, "Multitasking apps may only use background services for their intended purposes: VOIP, audio playback, location, task completion, local notifications, etc". Tapbots tried this and was rejected - they thought they could bypass it again by allowing the user to choose the audio, but they ended up going with the 10 minute task completion backgrounding I believe. – rcw3 Apr 25 '11 at 20:31