ALVersionControl
ALVersionControl 是一个应用更新过程控制器。下面将描述 3 种更新状态。AlVersionControl 不提供任何 api 调用。您必须以自己的方式实现。
版本控制 API 结构
请求
ALVersionControl 有一个名为 ALVersionControlRequest 的便捷请求模型,该模型仅包含 2 个变量。您可以在 api 调用时使用它。您必须在您的服务器数据库中存储 iOS 和 Android 的最新版本。
public struct ALVersionControlRequest: Encodable {
/// OS Type (1:iOS - 2:Android)
let os: Int
/// App bundle version (e.g. 1.0.2)
let version: String
public init() {
self.os = 1
self.version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
}
}
Json
{
"os": 1,
"version": "1.0.2"
}
响应
ALVersionControl 有一个名为 ALVersionControlResponse 的响应模型,您需要在使用过程中使用。您也可以用自己的模型,但必须在 "versionControllerAPIHandler" 方法中将其转换为该模型,以通过完成项。
public enum ALVersionControlStatus: Int, Codable {
/// All good. App is up to date
case upToDate = 0
/// Optional update available
case optional = 1
/// Force update available
case force = 2
}
public struct ALVersionControlResponse: Decodable {
/// The info message which inform to user there is a new update.
let message: String?
/// The status of new update.
let status: ALVersionControlStatus?
/// The market url which lead the user to update the app
let url: URL?
public init(message: String?, status: ALVersionControlStatus?, url: URL?) {
self.message = message
self.status = status
self.url = url
}
}
Json
{
"message": "Hey! You have a new update.",
"status": 1,
"url": "app market url"
}
- 当前版本是最新的 [0]:没有更新。一切正常。
- 可选更新[1]:为了通知用户有新的更新并且用户可以更新应用程序。一旦用户关闭提醒,我们不会再打扰。
- 强制更新[2]:用户必须更新应用程序才能继续使用该应用程序。希望永远不用它。
用法
设置
ALVersionControl.shared.setup(delegate: self)
您必须处理applicationDidBecomeActive状态。仅调用appDidBecomeActive方法就足够了。
func applicationDidBecomeActive(_ application: UIApplication) {
ALVersionControl.shared.appDidBecomeActive()
}
语言支持
土耳其语、英语、阿拉伯语
欢迎添加更多。接受拉取请求:)
安装
ALVersionControl可以通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中
pod 'ALVersionControl'
作者
sonifex, [email protected]
许可证
ALVersionControl受MIT许可证的许可。有关更多信息,请参阅LICENSE文件。