5

I have an iphone app that has a 30second process that does some network IO. Basically, while the app is in the background, i want this process to run every hour (actually once a day, but if it fails i want it to re-run in an hours time).

With the background features of ios 4, is this possible? If so, how? What are the limitations that i'll come up against?

Thanks so much!

Chris
  • 39,719
  • 45
  • 189
  • 235
  • 1
    I did a lot of research and found that "silent push notifications" did the trick for me. Check out http://stackoverflow.com/questions/35987366/ios-enterprise-app-how-can-i-make-sure-my-app-runs-in-the-background – Oded Regev Apr 13 '16 at 11:51

3 Answers3

6

Take a look at Apple's documentation about running code in the background.

http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html

There are few different ways of approaching backgrounded tasks. The only apps that can have fully backgrounded processes are "audio", "voip" and "location" apps, and this needs to be declared in the Info.plist.

If your app is not of this type, you'll probably find it difficult to do what you want easily. There are methods which allow you to keep your app alive in the background for a finite period of time (also at that link), but eventually your app will be shut down.

Local Notifications will only prompt the user to open the app - do you really want to have an alert pop-up on the phone every 30 seconds?

Eoin
  • 767
  • 3
  • 12
  • Looks like there's no way to do what i want. Thanks for letting me know. – Chris Sep 03 '11 at 10:10
  • The link in this answer is dead. You can find info about background processing in the current iOS docs at http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html – Opsimath Apr 22 '13 at 22:04
  • I am using location in my app but once I go in background and stays there for more than 30 seconds then my app got killed. – shaqir saiyed Mar 13 '20 at 11:37
1

I was making some kind of similar research, have a look at this SO answer in case you didn't manage to find it before. Applications like DataMan or Data Usage must have some sort of periodic code execution in the background, so I'm not 100% convinced that what you're asking for is impossible..

Community
  • 1
  • 1
phi
  • 10,634
  • 6
  • 53
  • 88
  • Looks intriguing, but i'm pretty sure that kindof hacky solution would get me kicked out of the app store pronto! – Chris Sep 04 '11 at 23:31
0

I believe that Using Local notifications will help.... check following....

  1. http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1
  1. An application can create and schedule a local notification, and the operating system then delivers it at the schedule date and time. If it delivers it when the application is not active in the foreground, it displays an alert, badges the application icon, or plays a sound—whatever is specified in the UILocalNotification object. If the application is running in the foreground, there is no alert, badging, or sound; instead, the application:didReceiveLocalNotification: method is called if the delegate implements it.

  2. The delegate can inspect the properties of the notification and, if the notification includes custom data in its userInfo dictionary, it can access that data and process it accordingly. On the other hand, if the local notification only badges the application icon, and the user in response launches the application, the application:didFinishLaunchingWithOptions: method is invoked, but no UILocalNotification object is included in the options dictionary.

Mohammad
  • 1,636
  • 1
  • 13
  • 17
  • Local notification allows you to popup an alert message from springboard, update app icon's badge number, or play a sound. But it never gives you any chance to do network I/O. – Chris Chen Sep 03 '11 at 08:05
  • hi, Thanks for info. I wrote above based on following. 1. application:didReceiveLocalNotification: Refer to discussion. they said that it could be whatever that UILocalNotification object contains. 2. In Overview part of UILocalNotification: "The delegate can inspect the properties of the notification and, if the notification includes custom data in its userInfo dictionary, it can access that data and process it accordingly. ".... So I thought userinfo dict can have a URL to call and it may call it and process data if process can be completed within specific time allowed for background process – Mohammad Sep 03 '11 at 08:20