Question

I need to keep the app to send a simple GET request ("ping") to the server every minute just for it to know that user is still online. I have no problem with it while the app is active and 10 minutes after it went background using "beginBackgroundTaskWithExpirationHandler".

But how can I keep request repeated all the time unless user terminates app manually?

Was it helpful?

Solution

That's not really how it works -- it's not a Windows or a Mac app that runs continually in the background.

What you probably want to do is use the background fetch process, whereby iOS will periodically run a particular method allowing you to do network operations while your app is in the background (or not running at all).

What this won't allow you to do is ping your server exactly once every minute. But actually that's a good thing. Consuming a users battery and data allowance like that is not very user-friendly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top