- 了解 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...
-
find -uid 可以找目錄下特定使用者有的檔案, 反過來不知怎麼找。 今天靈機一動, 想到可以這麼搞, 不夠直接, 至少能用就是了: ls -lR DIR | grep "^[-rw]\{10\} " | grep -v USER 2011-01-...
-
昨天意外發現 rsync 有 -z 的參數, 可以壓縮再傳。好奇它的效果就試了一下, 結果得到出人意外的結論: 有時候直接全部重新複製還比較快........, 雖然是很明顯的事實, 用慣 rsync 後到沒想到這點。 簡易的測試環境如下: 原始檔案: 一堆目錄合起來 7G...
-
以使用 LevelDB 為例。 抓好並編好相關檔案,編譯方式見第三方函式庫附的說明: $ ls include/ # header files leveldb/ $ ls out-shared/libleveldb.so* # shared library out-sha...
沒有留言:
張貼留言