iOS应用中通过设置VOIP模式实现休眠状态下socket的长连接
sockets,包括那个用于连接voip 服务的socket。因此,当程序运行时,它需要一直从头创建socket。
- - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)connectedPort{
- [socket performBlock:^{
- [socket enableBackgroundingOnSocket];
- }];
- }
- BOOL backgroundAccepted = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }];
- if (backgroundAccepted)
- {
- NSLog(@"VOIP backgrounding accepted");
- }
If
you want to let your VOIP application run in background , except those
base settings in plist file, you need a TCP socket who's property is set
to VOIP, than the iOS system will
take care this socket for you, when your application enter background ,
every thing was 'sleep' except that tcp socket. and if VOIP server send
some data thought that TCP socket, your application will be awake up
for 10 secs. during this time, you can post
a local notification.
Tcp socket can be set as VOIP Socket. But from i know , mostly VOIP
application are based on UDP socket. if you do not want to separate the
control socket from the data socket.
you should create another tcp socket which is focus on 'awake' your
application , and from my personal experience , it's very hard to keep
this 'awake' signal and the real sip control signal synchronize, the
application always miss the sip invite request.
best way is separating the sip control single from the UDP data socket ,
make it as a tcp socket , this is the best solution , but never use tcp
socket to transfer voice data.
dirty way: keep the application awake all the time. As i said , each
TCP single the application received thought that 'VOIP' tcp socket ,
will keep application awake for
10 seconds, so at the end of this duration(after 9 secs) , you can send
a response to the server to ask for another signal , when the next
signal arrived, the application will be awake again,after 9 secs , send
response again. keep doing this, your application
will awake forever.
https://github.com/robbiehanson/CocoaAsyncSocket
iOS应用中通过设置VOIP模式实现休眠状态下socket的长连接的更多相关文章
- [转] iOS应用中通过设置VOIP模式实现休眠状态下socket的长连接
转自:http://blog.csdn.net/missautumn/article/details/17102067 如果你的应用程序需要在设备休眠的时候还能够收到服务器端发送的消息,那我们就可 ...
- ios系统中各种设置项的url链接
ios系统中各种设置项的url链接 在代码中调用如下代码:NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];[[UIApplic ...
- ios开发中全局变量设置和调用方法
ios开发中,全局变量设置和调用方法如下:在AppDelegate.h文件中设置全局变量:@interface ***AppDelegate{NSString *myName;}@property ( ...
- [ios2]ios系统中各种设置项的url链接
在代码中调用如下代码:(ps: ios 5.0 以后不可用)NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];[[UIAppli ...
- IOS 应用中从竖屏模式强制转换为横屏模式
在 iPhone 应用里,有时我们想强行把显示模式从纵屏改为横屏(反之亦然),CocoaChina 会员 “alienblue” 为我们提供了两种思路 第一种:通过人为的办法改变view.transf ...
- [iOS] iOS系统中各种设置项的url链接
在代码中调用如下代码:NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];[[UIApplication sharedApplic ...
- 在IOS应用中从竖屏模式强制转换为横屏模式
http://www.cnblogs.com/mrhgw/archive/2012/07/18/2597218.html 在 iPhone 应用里,有时我们想强行把显示模式从纵屏改为横屏(反之亦然), ...
- IOS中快速集成短信SDK验证开发(SMSSDK),IOS开发中如何设置手机验证码
[转载请注明出处] sdk是别人的,我只是下载来集成一下. smssdk下载网站:http://www.mob.com/(也有其他很多网站有类似SDK,譬如https://www.juhe.cn/等等 ...
- 如何在 iOS 8 中使用 Swift 实现本地通知(下)
在上集中,我们已经构建了一个简单的待办列表应用(to-do list app),这个应用可以在待办项过期时通过本地通知提醒用户.现在,我们要在之前的基础上添加以下功能:应用图标角标上显示过期待办项的数 ...
随机推荐
- mysql的小知识点(关于数据库的导入导出 对于windows)
对于,一个存在的数据,我们该如何去打包成.sql属性的文件呢? 直接进行这两条语句: D:\Program Files\MySQL\mysql\bin>mysqldump -u root -p ...
- Reorder List [LeetCode]
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...
- js-分享107个js中的非常实用的小技巧(借鉴保存)
转载原文:http://***/Show.aspx?id=285 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:doc ...
- <<薪资至少10K的一道题,你能拿下吗>>练习
偶尔要写写算法,是我平时用来保持感觉的常用的方法.今天看到园子里一面试题,看了一下感觉也能实现,不过过程确实艰的,自认为自己对算法的感觉还不错.不过这题确实我也用了差不多一下午的时间,基本上把工作时间 ...
- offsetLeft,Left,clientLeft的区别
offsetLeft,Left,clientLeft的区别 假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的 ...
- PHP中MySql函数收集
1.array mysql_fetch_assoc ( resource $result ) 从结果集中取得一行作为关联数组 说明: 返回对应结果集的关联数组,并且继续移动内部数据指针. 参数:re ...
- Mysql复制表格
1.复制表结构及数据到新表 CREATE TABLE 新表 as SELECT * FROM 旧表 不过这种方法的一个最不好的地方就是新表中没有了旧表的primary key.Extra(auto_i ...
- 如何在 Linux 上用 SQL 语句来查询 Apache 日志
Linux 有一个显著的特点,在正常情况下,你可以通过日志分析系统日志来了解你的系统中发生了什么,或正在发生什么.的确,系统日志是系统管理员在解决系统和应用问题时最需要的第一手资源.我们将在这篇文章中 ...
- JS对象的写法
写法1: <script> var database = function () { function add(){ console.info("add"); } fu ...
- 在ASP.NET MVC中使用Area
前言: 这段时间小猪花了不少功夫在研究ASP.NET MVC的源码上面,可谓思想是了解了不少,用的上用不上却是另外一回事了.! 应用场景: ASP.NET MVC中,是依靠某些文件夹以及类的固定命名规 ...