There are several thread on this topic and nothing which works for me. I don't have to deploy the app in the app store, so I can do hacks in the app to keep it running. Any way I can keep the app going even when it is backgrounded? Any pointers appreciated.
Asked
Active
Viewed 3,985 times
2
-
What exactly are you trying to achieve. There are various background modes you can use, but essentially you can't keep an app running forever - it may be terminated due to memory pressure, for example, but you can use some background modes to get iOS to re-launch your app in the background – Paulw11 Oct 02 '14 at 01:38
-
1The device needs to continuously fetch data every 30 seconds and act on it based on what it gets back from the server. I understand the push is the righ mechanism here but we can't do that right now, so we have to poll. Since if the app is backgrounded, we can't run this every 30 seconds, I was trying to find other ways. – user3570727 Oct 02 '14 at 02:13
-
Any thoughts or pointers please? – user3570727 Oct 02 '14 at 21:12
-
You can look at the VoIP background mode since you aren't going to put the app in the App Store, but there isn't really any way you can guarantee continual background execution. – Paulw11 Oct 02 '14 at 22:27
-
I tried, that but for the VoIP background mode it requires a ping from external side right? I don't think you can use a timer to fire continuously in the background forever. – user3570727 Oct 02 '14 at 23:09
-
Yes, that is why I don't think you can do what you want – Paulw11 Oct 03 '14 at 00:18
-
Sigh.. how does Google Maps run int he background.. it has to do something where it gives you directions while you are moving.. I am fine even getting that in.. – user3570727 Oct 03 '14 at 02:22
-
They are using the location background mode for directions - triggered by the location update – Paulw11 Oct 03 '14 at 02:23
1 Answers
4
I found this github project solving this problem: https://github.com/voyage11/Location Obviously Apple wouldn't approve this hack, but I guess it would work in your case.
Basically what you have to do is:
- Use the location background mode capability in info.plist
- Always have background task running, but don't let it run for longer than a minute. Create a new background task every minute and stop old task.
- Apart from the previous task rolling, also keep a long running background task. I'm not sure though if that is really needed.
- Start the location manager every minute and requestAlwaysAuthorization.
Some important snippets from the referenced code:
Background task:
bgTaskId = [application beginBackgroundTaskWithExpirationHandler:^{
[self.service debugLog:[NSString stringWithFormat:@"BG....background task %lu expired", (unsigned long)bgTaskId]];
}];
And start the location manager:
if(IS_OS_8_OR_LATER) {
[_locationManager requestAlwaysAuthorization];
}
[_locationManager startUpdatingLocation];

davvs
- 1,029
- 1
- 11
- 18