SwiftyUpdateKit is a framework for iOS and macOS. This framework supports for a user to update your app when new app version is released on the App Store.
| OS | version |
|---|---|
| iOS | 13.0+ |
| macOS | 10.15+ |
- Swift 5+
SwiftyUpdateKit is available through Swift Package Manager. To install it using Xcode, specify the git URL for SwiftyUpdateKit.
https://github.com/HituziANDO/SwiftyUpdateKit.git
SwiftyUpdateKit is available through Carthage. To install it, simply add the following line to your Cartfile:
github "HituziANDO/SwiftyUpdateKit"
SwiftyUpdateKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SwiftyUpdateKit"import SwiftyUpdateKitTo initialize this framework, you use SUK.initialize method in application(_:,didFinishLaunchingWithOptions:) method (macOS: applicationDidFinishLaunching(_:) method) of AppDelegate. See following:
let config = SwiftyUpdateKitConfig(
// Current app version.
version: Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String,
// iTunes ID.
// e.g.) The App Store URL: "https://apps.apple.com/app/sampleapp/id1234567890" -> iTunesID is 1234567890
iTunesID: "1234567890",
// The App Store URL of your app.
storeURL: "https://apps.apple.com/app/your-app/id1234567890",
// The country code used by iTunes Search API.
// See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for a list of ISO Country Codes.
country: "us",
// The method to compare the app version.
versionCompare: VersionCompare(),
// The update alert's title.
updateAlertTitle: "Released new version!",
// The update alert's message.
updateAlertMessage: "Please update the app. Please refer to the App Store for details of the update contents.",
// The update button's label.
updateButtonTitle: "Update",
// The remind-me-later button's label. If nil is specified, the button is hidden.
// That is, you can force a user to update because it cannot be canceled.
remindMeLaterButtonTitle: "Remind me later",
// (Optional) The count of retry when iTunes Search API failed. Default value is 2.
retryCount: 2,
// (Optional) Retries iTunes Search API after this delay in seconds. Default value is 1 second.
retryDelay: 1,
// (Optional) If true, the database is in development environment.
// Otherwise it is for production environment.
// Must set false when release your app.
development: {
#if DEBUG
return true
#else
return false
#endif
}()
)
SUK.initialize(withConfig: config)Calling initialize again does not invalidate work that is already queued or in progress. Those
operations continue with the configuration and environment captured when they started. Call
SUK.reset() before reinitializing when the existing operations must be cancelled.
To check whether new version is released, you use SUK.checkVersion method in viewDidAppear method of the view controller. See following:
iOS
SUK.checkVersion(VersionCheckConditionAlways(), newRelease: { [weak self] newVersion, releaseNotes, firstUpdated in
guard let self = self else { return }
SUK.showReleaseNotes(from: self, text: releaseNotes, version: newVersion) {
// Release Notes has been closed.
}
}) { [weak self] in
guard let self = self else { return }
SUK.requestReview(RequestReviewConditionAlways(), in: self.view)
}macOS
SUK.checkVersion(VersionCheckConditionAlways(), newRelease: { [weak self] newVersion, releaseNotes, firstUpdated in
guard let self = self else { return }
SUK.showReleaseNotes(from: self, text: releaseNotes, version: newVersion) {
// Release Notes has been closed.
}
}) { [weak self] in
guard let self = self else { return }
SUK.requestReview(RequestReviewConditionAlways(), in: self)
}First, this code shows the update alert if current app version is old.
Next, when new app version is installed, it shows the release notes of your app's the App Store page.
Finally, if the app version is latest and the release notes have already shown, it requests the review about your app.
VersionCheckConditionDaily and VersionCheckConditionLaunchingAndDaily record the current
date only after the App Store returns a valid app version. A failed lookup does not consume that
day's check, so the next call can try again.
Daily review conditions record the date when SwiftyUpdateKit calls the StoreKit review request API. StoreKit does not report whether it displayed the review interface, so this date represents an attempt. Conditions that skip the first day initially record the first evaluation date and do not make a review request on that day.
You can use custom UI to show the update alert and the release notes. See following:
SUK.checkVersion(VersionCheckConditionAlways(), update: { [weak self] newVersion, releaseNotes in
guard let self = self else { return }
// This closure is called when current app version is old.
// Show custom update alert: present your view controller or add your view for the update alert.
}, newRelease: { [weak self] newVersion, releaseNotes, firstUpdated in
guard let self = self else { return }
// Show custom release notes: present your view controller or add your view to show the release notes.
}) {
// noop
}To show custom update alert, the view controller presents your view controller or adds your view for the update alert in update closure. To open the App Store page of your app, you use following method:
SUK.openAppStore()Resets the status for the current environment: stored dates of version check and request review conditions in persistent and in-memory storage, and the stored app version for the release notes. The reset completes synchronously and cancels in-flight and queued version checks, review requests, and update alerts that have not yet been presented. An update alert that is already visible keeps its captured configuration, and its Update button still opens the corresponding App Store page.
For example, you may use SUK.reset method during testing and development.
SUK.reset()Default version comparison method refers to here. If you need another comparison method, you implement the VersionComparable protocol and set it to versionCompare argument in the SwiftyUpdateKitConfig.
To make the document of this framework, you run following command on the Terminal. This script depends on jazzy.
jazzy -version
jazzy version: 0.14.3
./make_docs.sh


