4

I have made an application which needs to send Location and status update to server every 1 minute. I tried below ways but none of them helped me out. is there any solution for this?

1 - NSTimer - Many people suggested to do this way. but the problem is going to backgroundMode and it only works for 20 minutes. after that application stops sending data.

2 - BackgroundFetchMode - at beginning looks like the correct solution. But this ability do not guarantee to run application at every 1 minute. it has an algorithm that iOS decide which application should run.

This API is not like a timer task, system will decide when to call the handler depending on many constraints.so if you set timeInterval to 2.00f(2secs), handler is called for every 2+(minimum) secs.

3 - LocationUpdate - again this way do not works because it only run your application if you move at least 500 meter.

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

4 - Push Notifications - in an article said in this method you can run an application within defined time and it really does !

you can schedule a notification within defined schedule time. but the problem is showing notification to user. which I need something silent in Background.

Also , you can not run some code every 1 minute. it just show a notification to user. and user should tap on your notification and then didReceiveLocalNotification can be available and you can run the code.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 3
    iOS restricts developers heavily when it comes to background tasks, this is to combat battery drain, so no, no real way to achieve what you are asking without the app being in the foreground the whole time. – Fonix Aug 17 '15 at 09:38
  • You can send silent push notifications which will be delivered to your app if it hasn't been terminated, but it won't do it infinitely because your battery will go flat very quickly – Paulw11 Aug 17 '15 at 09:40
  • @Paulw11 how many is limitation of silent push notifications? – Ehsan Razm khah Aug 17 '15 at 10:48

1 Answers1

1

As Apple states in their documentation:

In iOS, only specific app types are allowed to run in the background:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that record audio content while in the background
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Apps that need to download and process new content regularly
  • Apps that receive regular updates from external accessories

Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.

You can read all about implementing and declaring those background tasks in the link. However, if yours is another type of App, or you cannot use the system frameworks, there is no way for your App to run in the background indefinitely. And even if it is, you should always expect that the system stops your task for some reason (f.e. restarting the phone).

Daniel
  • 20,420
  • 10
  • 92
  • 149