📲 应用版本

不要让您的用户卡在您应用的旧版本上。
- 使用 语义版本控制 自动更新跟踪
- 内置 UI 提醒
- 丰富的代理方法集
- 完全文档化
- 良好的测试覆盖率
- 小的代码库
- 无外部依赖
- 通过所有主要包管理器提供:CocoaPods、Cartage 和 Swift 包管理器
目录
屏幕截图
更新 UI 警报
- 可跳过警报
- 不可跳过警报(默认)
- 阻塞警报
自定义 UILabel 和 UITableView 页脚
- 有四种格式化选项可用(
AppInfo.VersionFormat
)- 简短版(版本唯一): 1.0.0
- 简短版(含应用名称): AppVersion 1.0.0
- 长版(版本+构建): 1.0.0(42)
- 长版(含应用名称): 1.0.0(42)
要求
- Swift 4.2
- Xcode 10 或更高版本
- iOS 11.0 或更高版本
安装
CocoaPods
AppVersion 通过 CocoaPods 提供使用。要安装它,请将以下行添加到 Podfile 中
pod "AppVersion.swift"
Carthage
如果您使用的是 Carthage,请在您的 Cartfile
中添加 AppVersion
github "amebalabs/AppVersion"
请确保将 AppVersion.framework
添加到“链接框架和库”和“复制框架”构建阶段。
Swift 包管理器
待定
使用说明
在AppDelegate.swift中设置AppVersion,代码自解释
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let appVersion = AppVersion.shared
appVersion.updateFrequency = 1 // I want to check for updates once a day
appVersion.alertsEnabled = true // I want UI alerts, presenting update options
appVersion.alertType = .skippable // I want UI alert to include "Skip" button
appVersion.neverEnabled = true // I want UI alert to include "Never" butoon
appVersion.alertPresentationStyle = .actionSheet // I want UI presented as an actionSheet
appVersion.checkBeforeUpdatePresented = { // I want to present UI only if App Store version has more than 1 review and average rating is higher than 3
return (appVersion.appStoreVersionInfo?.ratingsCount ?? 0) > 1
&& (appVersion.appStoreVersionInfo?.averageRating ?? 0) > 3
}
appVersion.run()
return true
}
代理
作为代理提供的有意义的更新跟踪事件(AppVersionDelegate
)。所有代理都是可选的,因此您可以只实现所需的代理。即使禁用了 UI 提醒,也可以使用代理,例如,您可以选择实现自己的 UI。请参阅文档以获取更多详细信息。
UILabel 和 UITableView
使用Storyboard
在Storyboard中创建 AppVersion 标签:将 UILabel 拖到Storyboard上并设置类为 AppVersionLabel
然后设置格式名称在属性检查器中:[图片见原文链接](#)
AppVersionLabel
以编程方式创建 let versionLabel = AppVersionLabel()
versionLabel.format = format
versionLabel.textAlignment = .center
versionLabel.textColor = .red
在UITableView脚注中添加版本
tableView.addVersionFooter(with: .longWithName)
或
tableView.addVersionFooter(with: .long, alignment: .right, textColor: .lightGray, footerHeight: 22)
作者
- 网站:Ameba
- Github @amebalabs
许可
AppVersion遵循MIT许可。请参阅LICENSE文件以获取更多信息。