iOS VOIP app does not accept new socket connections in background - ios

I am trying to implement an iOS VOIP application.
I am using GCDAsyncSocket to listen on a port for connections. I did add the required background modes in info.plist and also registered the readstream and writestream to kcfNetworkServiceTypeVOIP.
I also added KeepAliveTimeOutHandler to wake up the app. The handler block just prints the wake up time to stdout.
As long as app is in foreground new connections are accepted but when the app is in background, the app is not waken and all the connections attempted are sent to the socket when the app moves to foreground again.
I searched through many solutions but could not get it to work.
Thanks in advance.

I am not sure if it is still relevant for you but in case someone else reads this question.
As discussed in other similar question on stackoverflow in this one for example you can have only one socket which is in NetworkServiceTypeVOIP mode. Otherwise both of them will not work and your app will not wake up and not accept new connections.

Related

In Backgrond WebRTC offer is not working in iOS

In WebRTC i m giving offer when the app is open and working fine and when it goes to background or Phone is unlock offer is not going.How offer can be sent.Can any one help me.
You have several ways to implement this
1) declare your application as VOIP. This kind of application is allowed to have one signalling socket working even in background mode; you should use setKeepAliveTimeout:handler: method as well in order to keep your socket connection active. As soon as new data will be ready for reading on this socket your application will be awaken and you can send local notification to let user know about incoming call. But this approach is deprecated and isn't battery friendly.
2) Simple way is you can just make use of voip push notifications.

iOS Backgrounding mode Location Updates - but also keep a socket open

I have a navigation application that works with both CoreLocation (Backgrounding mode Location updates) as well as GPS data provided over a UDP connection from an external sensor.
I've noticed that when I background the app the socket goes down (which likely makes sense).
What is the procedure to keep the socket open in backgorunding?
Idea
I thought perhaps to register as a VoIP app - would keep the socket open but it looks like that works differently now.
The documentation suggest implementing setKeepAliveTimeout:handler: but this appears to be deprecated.
I'm not sure exactly how to proceed. Any ideas? The best I can come up with is a hack to have my location-update handler run a check on the socket so see if there is new data - but I'm assume there is a legitimate way to do this.
When the phone goes in stand-by all the UDP socket are closed and only TCP connection can be used. Yes probably with VOIP app you can use the UDP but in that case your app will be reject because your don't use a real VOIP service. I had the same problem ... In my case, even if the phone is in background, I want to send UDP message to a domotic system but is not possible.

Obtaining Wifi connectivity notification while in background

Is it possible to get notifications about Wifi connectivity state while an iOS app is running in the background? It is looking like a no, but I am also curious if this could be checked during a background fetch routine.
You have limited options to get processor time while in background and as far as I know there is no direct option to be notified on the WiFi status. Here you can find the modes of background execution: apple docs
I have tried with VOIP support to keep a stream opened while the app was in background. Everything worked ok and I was getting connectivity errors when the connection was lost, also I was able to try to reconnect from time to time until the connection was back on.
The only problem is that Apple will not approve the app unless your app provides a VOIP functionality (although the first two versions of the app were approved and only on the third one it got rejected because of flagging VOIP but not actually providing it).
I hope this helps.

how to hook ios connection changes

I'm working on a VOIP project.
My app uses reachability to listen when the connection changes and to re-register with SIP SERVER. Everything works well when the app is in the foreground.
But when My App enters the background, it can't catch connection changes. At least 10 minutes later (when keepAlive runs) my app can check the connection again.
I intend to look at connection changes (lost wifi, 3G change to wifi, wifi to 3G, ...) using a private framework and mobile substrate. I've tried many methods but have not found a working one yet.
Does anyone know which method will be called when connection changes ?
Thank you
i think only Reachability class is better for this even apple use this class for his code please see this Link in this code you find. you answer some how
I found a question from someone going through a similar scenario:
How to get Reachability Notifications in iOS in Background when dropping Wi-Fi network?
Hope this helps.
Make sure your app is setup to do VoIP in the background. In your Info.plist file. Add the following key value pair:
See also: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

How to keep socket alive in ios?

I'm doing a VOIP project on iPhone. I have the problem to keep the socket alive.
I already configured one socket for VOIP usage, and set kCFStreamNetworkServiceTypeVoIP for CFReadStreamRef and CFWriteStreamRef.
When my app runs in the foreground and I don't do any action, after 1 minute iPhone will sleep, black screen. My socket is still connected to the server.
But when my app runs in the foreground I press home button, and don't do any action, about 1 minute iPhone will sleep, then my socket disconnects from server.
Please help me.
First, have you read Tips for Developing a VoIP App? From your description, it sounds like you haven't set UIBackgroundModes to voip. You also likely will need to configure a keep alive handler.

Resources