ForceUpdateKit 0.0.11

ForceUpdateKit 0.0.11

maziarsaadatfar 维护。



  • 作者
  • Maziar Saadatfar

ForceUpdateKit

ForceUpdateKit

Languages
Platform Version SPM compatible

SWIFT

ForceUpdateKit 此仓库用于检查应用强制更新以及处理更新流程。

特性

  • 强制更新 不需实现服务器和客户端
  • 多样 风格和配置。
  • 兼容 所有平台

示例

示例1 - 全屏1

全屏1

例如:

Task {
    await ForceUpdateKit().configure()
 }

示例2 - 全屏2

全屏2

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .fullscreen2
    await ForceUpdateKit().configure(config: config)
 }

示例3 - 全屏3

全屏3

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .fullscreen3
    await ForceUpdateKit().configure(config: config)
 }

示例4 - 全屏4

全屏4

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .fullscreen4
    await ForceUpdateKit().configure(config: config)
 }

示例5 - 弹出框1

弹出框1

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .popover1
    config.viewConfig.contentViewBackColor = .black
    config.viewConfig.popupViewBackColor = .black
    config.viewConfig.headerTitleColor = .white
    config.viewConfig.updateImageType = .gear
    config.viewConfig.updateImageColor = .orange
    config.viewConfig.updateButtonBackColor = .orange
    config.viewConfig.versionTextColor = .orange
    await ForceUpdateKit().configure(config: config)
 }

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .popover1
    config.viewConfig.contentViewBackColor = .clear
    config.viewConfig.popupViewBackColor = .black
    config.viewConfig.headerTitleColor = .white
    config.viewConfig.updateImageType = .gear
    config.viewConfig.updateImageColor = .orange
    config.viewConfig.updateButtonBackColor = .orange
    config.viewConfig.versionTextColor = .orange
    await ForceUpdateKit().configure(config: config)
 }

示例6 - 弹出框2

弹出框2

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .popover2
    config.viewConfig.contentViewBackColor = .black
    config.viewConfig.popupViewBackColor = .black
    config.viewConfig.headerTitleColor = .white
    config.viewConfig.updateImageType = .gear
    config.viewConfig.updateImageColor = .orange
    config.viewConfig.updateButtonBackColor = .orange
    config.viewConfig.versionTextColor = .orange
    await ForceUpdateKit().configure(config: config)
 }

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .popover2
    config.viewConfig.contentViewBackColor = .clear
    config.viewConfig.popupViewBackColor = .black
    config.viewConfig.headerTitleColor = .white
    config.viewConfig.updateImageType = .gear
    config.viewConfig.updateImageColor = .orange
    config.viewConfig.updateButtonBackColor = .orange
    config.viewConfig.versionTextColor = .orange
    await ForceUpdateKit().configure(config: config)
 }

服务配置

这是您要自定义的所有项的默认值 服务配置 类,您可以定义或为路由传入新值,或使用我们服务的默认值。

public struct UpdateServiceConfig {
    public var route: String = "https://my.api.mockaroo.com/forceupdate.json?key=2202ab40"
    public var appId: String = Bundle.main.bundleIdentifier ?? String()
    public var version: String = Bundle.main.releaseVersionNumber ?? String()
    public var viewConfig: ForceUpdateViewConfig = ForceUpdateViewConfig()
}

您可以定义或传递新值以用于路径,或者使用我们服务的默认值。

例如:

Task {
    let config = UpdateServiceConfig()
    config.route = "https://myapi.enpoint/forceupdate"
    await ForceUpdateKit().configure(config: config)
 }

视图和样式配置

这是您要自定义的所有项的默认值 视图配置 类,您可以定义或传递新值以用于路径,或者使用我们服务的默认值。

public class ForceUpdateViewConfig {
    public var style: ForceUpdateViewStyle = .fullscreen1
    public var updateButtonNortmalTitle: String = "Update New Version"
    public var updateButtonSelectedTitle: String = "Update New Version"
    public var updateButtonImage: UIImage = UIImage(named: "") ?? UIImage()
    public var contentViewBackColor: UIColor = .white
    public var popupViewBackColor: UIColor = .black
    public var popupViewCornerRadius: CGFloat = 15.0
    public var contentBackGroundImage: UIImage = UIImage(named: "",
                                                         in: Bundle.module,
                                                         compatibleWith: nil) ?? UIImage()
    public var updateImageType: ImageType = .spaceship1
    public var updateImage: UIImage?
    public var updateImageColor: UIColor?
    public var updateButtonFont = UIFont.systemFont(ofSize: 12, weight: .medium)
    public var headerTitleFont = UIFont.systemFont(ofSize: 13, weight: .bold)
    public var headerTitle = "It's time to update"
    public var headerTitleColor: UIColor = .black
    public var descriptionFont = UIFont.systemFont(ofSize: 12, weight: .medium)
    public var descriptionText = "It's time to update The version you are using is old, need to update the latest version in order to experience new features."
    public var descriptionTextColor: UIColor = .gray
    public var versionFont = UIFont.systemFont(ofSize: 10, weight: .bold)
    public var versionText = "Up to 12.349 version Apr 2024."
    public var versionTextColor: UIColor = .gray
    public var updateButtonBackColor: UIColor = .blue
    public var lineColor: UIColor = .lightGray
    public var updateButtonTitleColor: UIColor = .white
    public var updateButtonCornerRadius: CGFloat = 20.0
    public var updateButtonBorderWidth: CGFloat = 0.0
    public var updateButtonBorderColor: UIColor = .clear
}

例如:

Task {
    let config = UpdateServiceConfig()
    config.viewConfig.style = .popover2
    config.viewConfig.contentViewBackColor = .clear
    config.viewConfig.popupViewBackColor = .black
    config.viewConfig.headerTitle = "my header title"
    config.viewConfig.updateButtonCornerRadius = 30
    config.viewConfig.updateButtonBorderWidth = 1
    config.viewConfig.updateButtonBorderColor = .yellow
    config.viewConfig.headerTitleColor = .white
    config.viewConfig.updateImageType = .gear
    config.viewConfig.updateImageColor = .orange
    config.viewConfig.updateButtonBackColor = .orange
    config.viewConfig.versionTextColor = .orange
    await ForceUpdateKit().configure(config: config)
 }

安装

  • 手动安装
  • CocoaPods
  • SPM (Swift 包管理器)

手动安装

  1. 下载 源代码。
  2. 解压 zip 文件,只需将 文件夹拖动到您的项目中。
  3. 请确保选中 如需要则复制项目

CocoaPods

use_frameworks!
target '<Your Target Name>' do
    pod 'ForceUpdateKit'
end

Swift 包管理器

Swift 包管理器 是一种用于管理 Swift 代码分布的工具。它与 Swift 建筑系统集成为自动下载、编译和链接依赖项的过程。

要从 Xcode 项目中集成 ForceUpdateKit 使用 Swift 包管理器,将其添加到您的 Package.swift 的依赖项值中。

dependencies: [
    .package(url: "https://github.com/maziar/ForceUpdateKit.git")
]

教程

1. 入门

  • 通过代码入门

在 Appdelegate 或 SceneDelegate 或您需要的任何地方,您可以调用

import ForceUpdateKit

Task {
    await ForceUpdateKit().configure()
 }