Websocket connection in background without VOIP

Hello,


We need our app to be able to send coordinates in background and hold connection with server via websocktes. As far as I know, it is only possible for VOIP apps. Is it allowed to use "voip + location updates" even though our app doesn't have VOIP functionality.


Thanks,

The general rules for networking in the background are given in Technote 2277 Networking and Multitasking. In short, if you can prevent your app from suspending then networking in the background works just like networking in the foreground. So, if your app is executing—because of a significant location change, for example—you can use any networking API you like.

The only gotcha here is that, depending on how your app was resumed in the background, you may have a very short amount of time to do your networking (seconds). You can extended that to something more reasonable (tens of seconds) using a UIApplication background task. In most cases that’ll be enough to get your networking operation done, but you must make sure to code your app to deal with the case where it isn’t sufficient.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hey,


Thanks for the response. But we need to keep connection for hours some time. The case is:


1. Driver srtarts the ride

2. He taps "Navigate" and choosing 3rd party app (say, Waze)

3. He goes to Waze and drives.


But our app has to send coordinates to our service during all ride, non stop. Every second. No limit or interpatiopns. How is it possible?

Does that mean you’re using the

location
background mode? If so, your app will never get suspended and thus my earlier comment applies: if you can prevent your app from suspending then networking in the background works just like networking in the foreground.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,

But what can prevent app from suspending? Is it enough to set up "location" in Background Modes? Or in code i should use some special methods?


Thanks,
Nikita.

Is it enough to set up "location" in Background Modes?

No.

Or in code i should use some special methods?

You have to be actively tracking the user’s location. I’m not particular au fait with Core Location, so I’m not going to go into the specifics. However, I will say that this is more complex than it seems because the user’s movement has to match the activity type that you’ve told Core Location you’re tracking. WWDC 2012 Session 303 Staying on Track with Location Services has the details on this, but I wouldn’t be surprised if that’s made it into the formal documentation since then.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Websocket connection in background without VOIP
 
 
Q