Saving / caching files using AFNetworking and using it for online and offline access

Our application serves content in a UIWebView that can link to PDFs, video files, Doc files, etc. We also allow the user to access all this content (website and related files) offline by downloading all required files. After all the files are available locally, we would like the web view to use these local files even when the user is online.

  • If we set up NSURLCache big enough and use AFNetworking to download files and save it to disk will it work out of the box?
  • Is there a way to load the loaded content (files) into the cache and then load the content into the webview so that it uses the cached files?
+3


source to share


1 answer


You can achieve this by AFHTTPSessionManager

subclassing AFHTTPSessionManager

. Here you can check if the client is offline. And then you can change the caching policy or force the application to use the cached data.



if (![[AFNetworkReachabilityManager sharedManager] isReachable]) {
    [request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
}

      

+1


source







All Articles