AvdLee / AppUpdately

Fetch the update available status for iOS or macOS apps based on the bundle identifier.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AppUpdately

Fetch the update status for a given app bundle identifier, without the need of any remote configuration. Simply provide your app's bundle identifier and compare the resulting update status.

Supports macOS and iOS.

Usage

The fetcher automatically fetches the bundle identifier. You can use the following code example:

var cancellable: AnyCancellable?
cancellable = UpdateStatusFetcher().fetch { result in
    defer { cancellable?.cancel() }
    guard let status = try? result.get() else { return }

    switch status {
    case .upToDate:
        break
    case .updateAvailable(let version, let storeURL):
        // Use the information to present your update alert or view.
    }
}

Or with async/await:

Task {
    let fetcher = UpdateStatusFetcher()
    let status = try await fetcher.fetch()
    
    switch status {
    case .upToDate:
        break
    case .updateAvailable(let version, let storeURL):
        // Use the information to present your update alert or view.
    }
}

Update notifier

You can make use of the AppUpdateNotifier which takes care of keeping track of seen updates.

let updateNotifier = AppUpdateNotifier(userDefaults: standard)
updateNotifier.updateStatusIfNeeded()

print(updateNotifier.lastStatus) // For example: .upToDate

AppUpdateNotifier is an ObservableObject and can be used in SwiftUI. lastStatus is a published property which can be observed.

You can use updateNotifier.triggerPresenterIfNeeded(presenter: ...) to use as a simple trigger for presenting a view in response to an available update.

Installation

Swift Package Manager

Add https://github.com/AvdLee/AppUpdately.git within Xcode's package manager.

Manifest File

Add AppUpdately as a package to your Package.swift file and then specify it as a dependency of the Target in which you wish to use it.

import PackageDescription

let package = Package(
    name: "MyProject",
    platforms: [
       .macOS(.v10_15)
       .iOS(.v13)
    ],
    dependencies: [
        .package(url: "https://github.com/AvdLee/AppUpdately.git", .upToNextMajor(from: "1.0.0"))
    ],
    targets: [
        .target(
            name: "MyProject",
            dependencies: ["AppUpdately"]),
        .testTarget(
            name: "MyProjectTests",
            dependencies: ["MyProject"]),
    ]
)

License

AppUpdately is available under the MIT license. See the LICENSE file for more info.

About

Fetch the update available status for iOS or macOS apps based on the bundle identifier.

License:MIT License


Languages

Language:Swift 100.0%