[iOS] – Different action of AFURLSessionManager for different OS Version ?>

[iOS] – Different action of AFURLSessionManager for different OS Version

AFURLSessionManager  use to download file from internet, it’s provide some useful delegate to make sure developer can tracking process also error etc…

Back to the day, my current project was use AFDownloadRequestOperation which made a wrapper of AFHTTPRequestOperation to download file. But from AFNetworking 3.0, they drop the AFHTTPRequestOperation so we cannot use AFDownloadRequestOperation anymore.

We decide to use AFURLSessionManager instead of old library.

The problem is AFURLSessionManager has different action about the way it’s fire the delegate. Here is a simple block of download function of AFURLSessionManager:

After testing, I see that the destination block was fire only on OS >= 9.0 whenever the download task was fail or success. Why do we need to care about fail case? Yes, here is reason!

I’ll explain from my current project. When app call the download API, there are two case of the return result. If that download is valid then server will return byte by byte to app so app can execute the download normally otherwise server will return the response code is 500 (mean error) and an json inside the body content!!! That mean on OS >= 9.0 when server return error, you can get the json body content from destination path otherwise (OS < 9.0) there is no way to get the response data in that case.

That really pain for me and my current project. That enough for now, hope it can help someone, I’m going to release the hotfix about this problem now! See you guys in next topic :)

Leave a Reply

Your email address will not be published. Required fields are marked *