Introduction
The AppStoreVersion library is a powerful tool that allows developers to easily retrieve and monitor the latest version of their iOS app from the App Store. With this library, you no longer need to manually check for updates or rely on third-party services. It provides a simple and efficient way to keep your users informed about the latest version of your app.
Features
- Retrieve the latest version information from the App Store
- Automatically compare the latest version with the current installed version
- Check if an update is available for your app
- Display a custom update prompt to users
- Redirect users to the App Store for app updates
- Flexible configuration options
- Supports both Objective-C and Swift
Installation
You can easily integrate the AppStoreVersion library into your iOS project using CocoaPods. Simply add the following line to your Podfile:
// Add this line to your Podfile pod 'AppStoreVersion'
Usage
1. Import the AppStoreVersion module:
import AppStoreVersion
2. Instantiate the AppStoreVersion
object:
let appStoreVersion = AppStoreVersion.shared
3. Retrieve the latest version information:
appStoreVersion.fetchLatestVersion(appId: "YOUR_APP_ID") { (version, error) in if let latestVersion = version { // Handle the latest version information } else if let error = error { // Handle the error } }
4. Compare the latest version with the current installed version:
if let latestVersion = appStoreVersion.latestVersion { if appStoreVersion.isUpdateAvailable() { // Update is available } else { // Up to date } }
5. Display a custom update prompt:
if appStoreVersion.isUpdateAvailable() { let alert = UIAlertController(title: "Update Available", message: "A new version is available. Do you want to update now?", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Update", style: .default, handler: { action in // Redirect to the App Store appStoreVersion.redirectToAppStore() })) alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) // Present the alert self.present(alert, animated: true, completion: nil) }
Configuration
The AppStoreVersion library provides various configuration options to customize its behavior. You can modify these options by accessing the config
property of the AppStoreVersion
object.
Example:
appStoreVersion.config.checkInterval = 3600 // Set the check interval to 1 hour (in seconds) appStoreVersion.config.useFallbackCache = true // Enable fallback caching
List of available configuration options:
checkInterval
: Specifies the interval (in seconds) between version checks. Default is 86400 (24 hours).useFallbackCache
: Specifies whether to use a fallback cache. If enabled, the latest version will be cached for offline access. Default is false.
Conclusion
The AppStoreVersion library simplifies the process of retrieving and monitoring the latest version of your iOS app from the App Store. By integrating this library into your project, you can keep your users informed about updates and provide them with a seamless update experience. We hope you find this library useful and we welcome any feedback or suggestions you may have.