Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VoIP socket on iOS - no notifications received

I have a VoIP app that uses a TCP service to wake it up on incoming calls. The TCP socket is created with this code fragment:

CFReadStreamRef read = NULL;
CFWriteStreamRef write = NULL;
...
CFStreamCreatePairWithSocketToHost(NULL,(__bridge CFStringRef)shost, port, &read, &write);
self.read = (__bridge NSInputStream*)read;
self.write = (__bridge NSOutputStream*)write;
if (![self.read setProperty:NSStreamNetworkServiceTypeVoIP
                     forKey:NSStreamNetworkServiceType]){
    [Log log:@"Could not set VoIP mode to read stream"];
}
if (![self.write setProperty:NSStreamNetworkServiceTypeVoIP
                      forKey:NSStreamNetworkServiceType]){
    [Log log:@"Could not set VoIP mode to write stream"];
}
self.read.delegate = self;
self.write.delegate = self;
CFRelease(read);
CFRelease(write);
[self.read scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.write scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.read open];
[self.write open];

I've also set the following:

  1. VoIP & Audio in the info plist
  2. Keep alive timer using [UIApplication sharedApplication] setKeepAliveTimeout
  3. UIRequiresPersistentWiFi = YES in the info plist (quite sure it's not required, but...)

This works well while the app is in the foreground, and even works well in the background for a few minutes, but after a few minutes - the app does not receive any new TCP messages. It doesn't work on wifi or 3G, same result for both.

I also tried setting the property just to the read stream (though the read and write point to the same socket). Whenever I receive data on the TCP or send data I also start a short background task. BTW - everything takes place on the main thread.
I've checked if the app crashes - it doesn't.
The same behavior can be observed while debugging on the device - after a while - nothing is received (no crashes, warnings, anything).

What am I doing wrong?

like image 673
Moshe Gottlieb Avatar asked Aug 21 '12 14:08

Moshe Gottlieb


People also ask

What is VoIP notification iOS?

VoIP notifications are background messages that don't generate alerts or sounds. These notifications are used to wake up apps and pass across information about incoming calls. With VoIP, mobile apps let users send and receive calls on their devices, using the app interface rather than the default phone interface.

Why are notifications not showing on my iPhone iOS 15?

Go to Settings → scroll down to the app. Tap Notifications. Ensure that Allow Notifications toggle is turned on.

How do I enable push notifications on iOS?

Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered—immediately or in the scheduled notification summary.


1 Answers

Looks like your code should work. But there may be two technical problems I can think of:

  1. If you try this from LAN connection, while app in background the LAN router can close passive TCP connection because, in this case, SIP stack(guess you use SIP protocol) can't send data keep alive every 15 to 30 secs like it would in foreground.

  2. Less likely, suppose you know what you doing, but since registration keep alive can be triggered only once in 10 minutes while in background, make sure that SIP server allows such a long expire period and you define it right in registration message.

like image 132
Ilya K. Avatar answered Sep 24 '22 03:09

Ilya K.