先說下網絡開源的sip產品:
1)PJSIP 這是一個開源庫,研究的不多,因為沒有那個時間去重最基本的區開發,畢竟不是專門做這方面的,所以直接去找做好的開源產品。
2)linphone 這是我最開始找到的開源產品,網上推薦率很高,音質十分清晰,適合做點對點語音,但是開始著手的時候遇到兩個問題,一 是國外資源封殺的厲害,資源十分難下載; 二 是其編譯實在麻煩,下了一堆庫和編譯環境,完全按照官網的步驟,發現還是有些地方編譯不過,在linphone上的編譯上就耗了我一周時間,最主要的還是網絡限制,大部分編譯環境和工具都得在國外網站下載,耗了比較多時間,一周之后,我果斷放棄linphone,繼續找其他開源產品。
3)siphon 在陸續找到很多開源sip產品后,最后選擇了siphon;兩個原因, 一 比較好編譯 二 音質還不錯,這個軟件基本的帶電話和接電話功能,不過經過使用發現其沒有后臺接電話功能,最扯是我快弄完的時候才發現沒有后臺。后臺部分下面后說到,這里只列舉下我遇到的開源sip產品。
4)idoubs 這個就牛B了,這是在我發現siphon沒有后臺后,在經過網上各種說如何實現VIOP后臺的帖子折磨后找到的一個開源軟件,音質和linphone不相上下,且實現點對點視頻功能,可以說滿足了大部分人得需求了,編譯也十分簡單,按官網步驟走即可,兩個文件夾,一個doubango庫,這是基礎庫,很好的封裝了sip電話的各種功能,比較大,大概850M;一個是idoubs,這個實現了sip電話的UI部分,這個才23M。這個最重要的是實現了后臺運行和接電話功能,就是可以home鍵切出后可以有來電提醒,不過這個和網上說的利用 TCP+socket 來實現后臺不同的是,這是利用后臺播放靜默音樂來實現,后臺部分也有些bug,如 接真實電話、音樂播放軟件后臺播放和暫停、微信的語音播放都會打斷這個靜默音樂的播放,導致后臺失敗,破解方法后面會說到。
雜談 一一 ios4之后 和 ios7新增 的后臺部分知識:
前言:iOS不是真正的多任務系統,在用戶按下Home按鈕后,所有應用程序都會進入后臺狀態,并且大部分都會迅速進入暫停狀態,應用程序的所有工作內存都在RAM中,在暫停時它完全不執行。因此,切換回這樣的應用程序非常快。但是如果系統需要更多的內存給當前處于活動狀態的應用程序,就有可能終結暫停狀態的應用程序,它們的內存也將被釋放。
一方面,應用程序在進入后臺狀態時,需要釋放一些資源,使自身的暫停快照更小,從而減少從RAM中清除的風險,另一方面,為了避免被終結而丟失用戶的數據,需要在用戶離開時保存他們的進度信息,這些工作,需要在5秒鐘內完成,不然會被系統認定有異常被強制退出。可能通過接收應用程序發送的通知
ios4及之后
1)請求后臺任務 (600s 以內)beginBackgroundTaskWithExpirationHandler ^{}
作用 : 可以切后臺后進行一些未完成的下載和比較重要的事情,如短時間的下載,消息的發送,未完成的上傳,反正在600s內app可以做任何事情。
注意:按home鍵后,會運行一段時間來執行代碼,如無代碼,3分鐘左右執行block。
按鎖屏鍵后,ios6及之前會活躍來執行代碼,但是在ios7中,后臺任務處理方式發生改變,鎖屏后后臺任務暫時暫停已節省電力,之后在特定時間如檢查郵件或接電話時,之前暫停的后臺任務一起執行,就是說,系統不會專門為第三方應用保存設備處于活動狀態。
用法:
- <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">- (<span style="color: #35568a">void</span>) doUpdate</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000"> [</span><span style="color: #35568a">self</span><span style="color: #000000"> </span>beginBackgroundUpdateTask<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; min-height: 21px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(207, 135, 36);"><span style="color: #000000"> </span>
- </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">- (<span style="color: #35568a">void</span>) beginBackgroundUpdateTask</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000"> </span><span style="color: #35568a">self</span><span style="color: #000000">.</span>backgroundUpdateTask<span style="color: #000000"> = [[</span><span style="color: #c35900">UIApplication</span><span style="color: #000000"> </span>sharedApplication<span style="color: #000000">] </span>beginBackgroundTaskWithExpirationHandler<span style="color: #000000">:^{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: 'Heiti SC Light'; color: rgb(207, 135, 36);"><span style="font-family: Menlo; color: rgb(0, 0, 0);"> </span><span style="font-family: Menlo;">
- </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: 'Heiti SC Light'; color: rgb(207, 135, 36);"><span style="color: rgb(207, 135, 36); font-family: Menlo; font-size: 18px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="white-space:pre"> <span style="color: rgb(207, 135, 36); font-family: Menlo; font-size: 18px; white-space: pre; background-color: rgb(240, 240, 240);">
- </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">- (<span style="color: #35568a">void</span>) endBackgroundUpdateTask</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000"> [[</span><span style="color: #c35900">UIApplication</span><span style="color: #000000"> </span>sharedApplication<span style="color: #000000">] </span>endBackgroundTask<span style="color: #000000">: </span><span style="color: #35568a">self</span><span style="color: #000000">.</span>backgroundUpdateTask<span style="color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(88, 126, 168);"><span style="color: #000000"> </span><span style="color: #35568a">self</span><span style="color: #000000">.</span>backgroundUpdateTask<span style="color: #000000"> = </span>UIBackgroundTaskInvalid<span style="color: #000000">;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo;">}</p><div>
- </div>
2)iOS在后臺每隔一段時間執行一下 (600s 以外) setKeepAliveTimeout : time handler : ^{}
作用:如app每隔一小時去刷新登錄的key值,避免key值失效。
注意:1)要成功調用該函數,就必須在Info.plist里設UIBackgroundModes鍵的array值之一voip字符串;
2)timeout必須>=600;
3)喚醒app的時間間隔是不精準的;
4)喚醒后只有10秒執行時間。即handler里的代碼要在10秒類執行完。10秒后app再次被阻塞。(可以 用-backgroundTimeRemaining屬性來查看返回剩余時間);
5)該函數成功調用后,在程序生命周期內有效,該函數的效果在回到前臺的狀況下,依然有效。(因此可以 把它當timer使.) ;
6)clearKeepAliveTimeout函數用來清除handler;
用法:1)在info.plist里加入UIBackgroundModes鍵,其值為數組,數組之一為voip字符串;
2)如下;
- <p style="font-family: Menlo; margin-top: 0px; margin-bottom: 0px; font-size: 18px;">- (<span style="color: #35568a">void</span>) viewDidLoad</p><p style="font-family: Menlo; margin-top: 0px; margin-bottom: 0px; font-size: 18px;">{</p><p style="font-family: Menlo; margin-top: 0px; margin-bottom: 0px; font-size: 18px; color: rgb(88, 126, 168);"><span style="color: #000000"> [</span><span style="color: #35568a">super</span><span style="color: #000000"> </span>viewDidLoad<span style="color: #000000">];</span></p><p style="font-family: Menlo; margin-top: 0px; margin-bottom: 0px; font-size: 18px; color: rgb(207, 135, 36);">
- </p><p style="font-family: Menlo; margin-top: 0px; margin-bottom: 0px; font-size: 18px; color: rgb(207, 135, 36);"><span style="color: #000000"> </span>
IOS7 新增的后臺功能
前言:
在iOS7之前,系統所接受的應用多任務可以大致分為幾種:
- 后臺完成某些花費時間的特定任務
- 后臺播放音樂等
- 位置服務
- IP電話(VoIP)
- Newsstand
iOS7后臺的變化在于以下四點:
- 改變了后臺任務的運行方式
- 增加了后臺獲取(Background Fetch)
- 增加了推送喚醒(靜默推送,Silent Remote Notifications)
- 增加了后臺傳輸(?Background Transfer Service)
1) 改變了后臺任務的運行方式 : 這個在上面有提到,ios7 鎖屏后 申請后臺任務后不是立馬運行
@import url(http://m.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
posted on 2016-11-04 18:05
聶文龍 閱讀(295)
評論(0) 編輯 收藏 引用