App版本更新 - Siren

2018-12-12  本文已影响24人  Dove_iOS

Tip1:上架app的版本更新弹窗提示,Siren会自动获取app在App Store的版本号,自动对比,可以设置一些可选参数,也可以重写一些代理方法

Tip2:大版本更新强制只能跳转App Store去更新,3秒后杀掉进程

//第一步 添加pods库
pod 'Siren', '~> 3.9.1'

//第二步 引入
import Siren

//第三步 创建
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    setupSiren()
}

//创建,基本参数
func setupSiren() {
    
    // Siren is a singleton
    let siren = Siren.shared
    
    //开启debug状态,打印请求回来的json数据
    siren.debugEnabled = true
    
    //设置提示按钮颜色
    siren.alertControllerTintColor = UIColor.normalTextColor()
    
    //大的更新 A.b.c
    siren.majorUpdateAlertType = .force
    //小的更新 a.B.c
    siren.minorUpdateAlertType = .skip
    //补丁更新 a.b.C
    siren.patchUpdateAlertType = .option
    //修订更新 a.b.c.D
    siren.revisionUpdateAlertType = .option
    
    //当前版本发布几天后显示警告,默认1天
    siren.showAlertAfterCurrentVersionHasBeenReleasedForDays = 3
    
    //版本检查频率 .immediately(立刻) with .daily(每天) or .weekly(每周)
    siren.checkVersion(checkType: .immediately)
}
//更新版本跳入App Store之后,延时3秒主动关闭App
func sirenUserDidLaunchAppStore() {
    if Siren.shared.alertType == .force {
        self.perform(#selector(closeApp), with: nil, afterDelay: 3)
    }
}

@objc func closeApp() {
    abort()
}

//用户提供更新对话框
func sirenDidShowUpdateDialog(alertType: SirenAlertType) {
    
}
//用户点击了按钮,跳转到AppStore应用上
func sirenUserDidLaunchAppStore() {
    
}
//用户点击了按钮,取消更新对话框
func sirenUserDidCancel() {
    
}
//用户点击了按钮,跳过版本更新
func sirenUserDidSkipVersion() {
    
}
//未能执行版本检查,返回系统级错误
func sirenDidFailVersionCheck(error: NSError) {
    
}
//版本检查成功的回调方法
func sirenDidDetectNewVersionWithoutAlert(message: String) {
    print("\(message)")
}

感谢 Arthur Sabintsev and Aaron Brager

原文
https://github.com/ArtSabintsev/Siren
简体中文
https://github.com/ArtSabintsev/Siren/blob/master/README.zh_CN.md
同时参考了 五月飞
https://www.jianshu.com/p/159325cdaf18

推荐文章:
https://www.jianshu.com/p/e27149aca054

上一篇下一篇

猜你喜欢

热点阅读