The App42 iOS SDK now supports iOS offline caching and storage that will make your iOS application responsive even if the network is not available so the user can use your application flawlessly without any trouble. iOS offline caching enables your application to read data from the local cache if the network is not available. Using this feature is quite straightforward and requires a single line of code to enable.
iOS caching data and iOS offline storage can be used in isolation or they can be used along with each other based on your app requirement. You can enable these features as explained below.
Caching allows an application to read data from its local cache depending on the policy that you have set. App42 allows three different cache policies, which we discuss below.
- APP42_CACHE_FIRST: This policy enables apps to first look for the cached response for all the READ requests and returns the valid cached data if available, otherwise the request will be sent to the server. A valid cached response means that the cached response is not expired.
- APP42_NETWORK_FIRST: This policy will try to send the request to the server if the network is available, otherwise it will look for the cached response.
- APP42_NO_CACHE: This is a default policy and follows the normal flow, i.e. it sends every request directly to the server.
Note: The expiry time for cached response is set by default to 24 hours, but you can always overwrite using our API, as explained below:
[code java][[App42CacheManager sharedCacheManager] setPolicy:APP42_CACHE_FIRST]; //Setting the Policy [[App42CacheManager sharedCacheManager] setExpiryInMinutes:<EXPIRY_TIME_IN_MINUTES>]; // Setting expiry time[/code]
Before talking about the details, let us go through some use cases.
- The user is playing your game and data, such as the score, needs to be saved to the cloud, but there is no network.
- The user wants to post his status in a social app and there is no network.
- The user wants to modify his existing note, but there is no network available.
There may be such use cases, and as a result, the application may lose the activity of that particular user, which may be a disappointment. This is where this feature will help. Offline storage allows the application to save requests (POST, PUT, and DELETE) locally in the application cache when it runs offline and sends them to the server when it goes online. Enabling this feature is a single-step process:
[code java][App42API setOfflineStorage:YES]; //Enabling Offline Storage[/code]
With the above two lines of code, you have enabled two great features in your iOS app.