Coder Social home page Coder Social logo

hituziando / swiftyupdatekit Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 2.46 MB

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.

License: MIT License

Swift 49.25% Objective-C 1.60% Shell 2.51% Ruby 0.59% C++ 46.05%
ios macos swift update ui

swiftyupdatekit's Introduction

SwiftyUpdateKit

release Pod Platform Pod Version Carthage Compatible Swift Package Manager compatible CI

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.

Supports

OS version
iOS 13.0+
macOS 10.15+

Requires

  • Swift 5+

Installation

Swift Package Manager

SwiftyUpdateKit is available through Swift Package Manager. To install it using Xcode, specify the git URL for SwiftyUpdateKit.

https://github.com/HituziANDO/SwiftyUpdateKit.git

Carthage

SwiftyUpdateKit is available through Carthage. To install it, simply add the following line to your Cartfile:

github "HituziANDO/SwiftyUpdateKit"

CocoaPods

SwiftyUpdateKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftyUpdateKit"

Usage

Import Framework

import SwiftyUpdateKit

Initialize

To 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)

Quick Usage

To check whether new version is released, you use SUK.checkVersion method in viewDidAppear method of the view controller. See following:

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.
    }
}) {
    SUK.requestReview(RequestReviewConditionAlways())
}

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.

Use custom UI

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()

Reset the status

Resets the status: stored date of version check condition, stored date of request review condition, and stored app version for the release notes.

For example, you may use SUK.reset method during testing and development.

SUK.reset()

Version Comparison Method

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.

API Reference

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

swiftyupdatekit's People

Contributors

hituziando avatar

Stargazers

PPGame Group avatar  avatar Xinran Liu avatar SoloX avatar Tetsuya Yuri avatar Kent Strong (Kento Yamazaki) avatar  avatar

Watchers

 avatar Kent Strong (Kento Yamazaki) avatar

Forkers

fironn

swiftyupdatekit's Issues

Utility.currentDate() crash

Crashed: com.apple.main-thread
0  App                  0x335440 specialized static Utility.currentDate() + 4332557376 (Utility.swift:4332557376)
1  App                  0x335558 VersionCheckConditionDaily.shouldCheckVersion() + 4332557656 (<compiler-generated>:4332557656)
2  App                 0x331a6c closure #1 in static SUK.checkVersion(_:update:next:) + 216 (SUK.swift:216)
3  App                  0x330054 thunk for @escaping @callee_guaranteed () -> () + 4332535892 (<compiler-generated>:4332535892)
4  libdispatch.dylib              0x63850 _dispatch_call_block_and_release + 24
5  libdispatch.dylib              0x647c8 _dispatch_client_callout + 16
6  libdispatch.dylib              0x45f18 _dispatch_main_queue_drain + 888
7  libdispatch.dylib              0x45b90 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 36
8  CoreFoundation                 0x93818 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
9  CoreFoundation                 0x77498 __CFRunLoopRun + 2096
10 CoreFoundation                 0x7bb48 CFRunLoopRunSpecific + 584
11 GraphicsServices               0x1984 GSEventRunModal + 160
12 UIKitCore                      0x375638 -[UIApplication _run] + 868
13 UIKitCore                      0x3752b0 UIApplicationMain + 312
14 SwiftUI                        0x190b30 OUTLINED_FUNCTION_895 + 2128
15 SwiftUI                        0x1074d8 block_copy_helper.1 + 320
16 SwiftUI                        0xf3e14 OUTLINED_FUNCTION_901 + 2360
17 App                  0x7194 main + 4329222548 (<compiler-generated>:4329222548)
18 ???                            0x1caa09df0 (Missing)

Crash due to Arabic locale?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.