可將 AFNetworking 封裝成 DataRequestManager,統一管理 GET、POST、上傳與下載。
類別內部建立 manager 或 sessionManager,對外提供 methodGetWithURL、methodPostWithURL、methodUploadWithURL 等方法,並用 delegate 回傳結果。
GET 適合取得資料,POST 適合送出參數。兩者都可在 success 與 failure block 中處理回傳。
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
[self.delegate passGetValue:responseObject];
} failure:nil];
使用 constructingBodyWithBlock 加入檔案資料,並指定 name、fileName 與 mimeType。
iOS 7 後可用 AFURLSessionManager 的 downloadTask,透過 resume、suspend 或 cancel 管理下載;若要續傳,需搭配 outputStream 與適當的快取策略。