- 了解 http request/response header 的用法, 看實例比較好懂: Sample http range request session - Stack Overflow
- NSURLConnection 連線 URL 所用的 scheme 為 http/https 時, 可放心在 callback 中將 NSURLResponse 往下轉型為 NSHTTPURLResponse, 這樣才能取得更多 http 特定的資訊 (如 http response header): iphone - When is a NSURLResponse not a NSHTTPURLResponse? - Stack Overflow
- 依 SDK 6.0 NSURLConnection.h 裡所說的, cancel 之後之後仍有可能呼叫 callback
The -cancel message hints to the loader that a resource load should be abandoned but does not guarantee that more delegate messages will not be delivered. If -cancel does cause the load to be abandoned, the delegate will be released without further messages. In general, a caller should be prepared for -cancel to have no effect, and internally ignore any delegate callbacks until the delegate is released.
感覺上除了 fail 或 finished 兩個 callback 之外, 其餘情況無法保證 NSURLConnection 的生命週期已結束。呼叫 cancel 後不能接著呼叫 release/autorelease, 否則可能會造成 crash。這和目前官網 (iOS v5.0) 所說得不同, 使用 cancel 時要留意一下實際情況。有過一些 async IO 開發經驗後, 可以理解為何不方便「保證 cancel 立即有效」, 但至少提供一個 "didCancel" 的 callback, 這樣才知道什麼時候可以 release NSURLConnection。
2013年1月27日 星期日
iOS 使用 NSURLConnection 實作續傳的注意事項
訂閱:
張貼留言 (Atom)
在 Fedora 下裝 id-utils
Fedora 似乎因為執行檔撞名,而沒有提供 id-utils 的套件 ,但這是使用 gj 的必要套件,只好自己編。從官網抓好 tarball ,解開來編譯 (./configure && make)就是了。 但編譯後會遇到錯誤: ./stdio.h:10...
-
UbuntuCompilationGuide – FFmpeg 說明如何在 Ubuntu 上安裝 ffmpeg 並包含 libx264 (支援 H.264)。全部安裝和移除的指令都有了, 超方便的。實測的結果, 用 libx264 壓出來的檔案又小畫質又好, 是必要的元件。 ...
-
最近有需求讀 C/C++ 的東西, 試了 ctags, cscope 覺得不理想。問了一下收到許多回應 ( G+ 、 plurk ), 真是太感謝大家了, 減少入門摸索的時間。 試用的感想如下: grep 優點 : 好上手 缺點 : 陽春 安裝 : 內建於 L...
-
最近被迫在短時間內學會 strace、gdb 這些之前一直用不到的重兵器, 都還不熟練就是了。剛好使用 hgsubversion 時有些困擾, 雖說它和 svn 整合得很好, 無縫接好 pull / push , 但它不會顯示 mercurial 對應到的 svn 版本, 平...
沒有留言:
張貼留言