iOS上的网络电话插座 - 没有收到通知 [英] VoIP socket on iOS - no notifications received

查看:166
本文介绍了iOS上的网络电话插座 - 没有收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用的TCP服务,唤醒呼入在VoIP应用程序。
TCP套接字与此code片段创建:

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和放大器;音频在信息的plist

  2. 保持活定时器使用[UIApplication的sharedApplication] setKeepAliveTimeout

  3. UIRequiresPersistentWiFi = YES在信息的plist(肯定它不是必需的,但......)

这工作得很好,而应用程序是在前台,甚至效果很好的背景了几分钟,但几分钟后 - 应用程序不接收任何新的TCP消息。
它不能在WiFi或3G,同样的结果工作两个。

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.

我也试过属性设置只是为了读取数据流(虽然读写指向同一插座)。
每当我收到的TCP数据或发送数据我也开始很短的后台任务。
BTW - 一切都发生在主线程上

我检查,如果应用程序崩溃 - 它不

可以在设备上调试观察到同样的行为 - 过了一会儿 - 没有收到(没有崩溃,警告任何东西)

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).

我在做什么错了?

推荐答案

看起来你的code应该工作。但是,可能有两个技术上的问题我能想到的:

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


  1. 如果您从LAN连接试试这个,而应用程序在后台LAN路由器可以关闭被动的TCP连接,因为在这种情况下,SIP协议栈(猜您使用SIP协议)不能发送数据永葆每15 30秒像它会在前台。

  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.

的可能性较小,假设你知道你在做什么,但因为注册永葆可以在10分钟内只能触发一次,而在后台,确保SIP服务器允许这么长的到期时间,你把它定义权注册消息。

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.

这篇关于iOS上的网络电话插座 - 没有收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆