Skip to content

SwapnanilDhol/UpdateAvailableKit

Repository files navigation

UpdateAvailableKit

UpdateAvailableKit is a lightweight package for checking whether an installed app has an update available and, when desired, showing an update banner UI.

Requirements

  • iOS 15.0+
  • tvOS 15.0+
  • watchOS 8.0+

Installation

Add UpdateAvailableKit with Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/SwapnanilDhol/UpdateAvailableKit", from: "2.0.0")
]

Usage

Quick Start

import UpdateAvailableKit

UpdateAvailableManager.shared.start()

Configuration

let configuration = UpdateAvailableConfiguration(
    bundleID: "com.example.app",
    cacheDuration: 7200
)

UpdateAvailableManager.shared.configure(with: configuration)
UpdateAvailableManager.shared.start()

Observe Results

import SwiftUI
import UpdateAvailableKit

struct ContentView: View {
    @ObservedObject private var updateManager = UpdateAvailableManager.shared

    var body: some View {
        Group {
            switch updateManager.result {
            case .updateAvailable(let newVersion):
                Text("Update available: \(newVersion)")
            case .noUpdatesAvailable:
                Text("No updates available")
            }
        }
    }
}

SwiftUI Banner

import SwiftUI
import UpdateAvailableKit

struct ContentView: View {
    @ObservedObject private var updateManager = UpdateAvailableManager.shared

    var body: some View {
        VStack {
            Spacer()

            UpdateAvailableBannerView(
                result: updateManager.result,
                appStoreID: "123456789"
            )
        }
        .onAppear {
            UpdateAvailableManager.shared.start()
        }
    }
}

Or provide a version string directly:

UpdateAvailableBannerView(
    newVersion: "2.3.0",
    theme: .default,
    appStoreID: "123456789"
)

The banner UI is available on platforms that support both SwiftUI and UIKit.

Core Types

public enum UpdateAvailableResult: Equatable {
    case updateAvailable(newVersion: String)
    case noUpdatesAvailable
}

Caching

Responses are cached in UserDefaults for 3600 seconds by default. Use UpdateAvailableConfiguration.cacheDuration to customize.

License

This project is licensed under the MIT License. See LICENSE.md.

About

A super easy way to check if the installed app has an update available. It is built with simplicity and customisability in mind and comes with pre-written tests.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages