Check if my IOS application is updated

前端 未结 8 1099
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 18:07

I need to check when my app launches if it was being updated, because i need to make a view that only appears when the app is firstly installed to appear again after being

8条回答
  •  我在风中等你
    2020-12-05 18:29

    I've created BundleInfoVersioning swift package to help me solve this issue.

    It works with all keys in the info dictionary, like CFBundleVersion or CFBundleShortVersionString and with custom key paths like, for example, NSAgora/DatabaseVersion.

    Examples:

    let bundleInfoVersioning = BundleInfoVersioning(bundle: .main)
    
    bundleInfoVersioning.check(forKeyPath: "CFBundleVersion") { (old: String?, new: String?) in
        if old == nil {
            Analytics.install(version: new)
        }
        else {
            Analytics.update(from: old, to: new)
        }
    }
    
    bundleInfoVersioning.check(forKeyPath: "CFBundleShortVersionString") { _ , newVersion in
        self.showWhatsNew(in: newVersion)
    }
    
    bundleInfoVersioning.check(forKeyPath: "NSAgora/DatabaseVersion") { (old: Int?, new: Int?) in
        self.resetDataBase()
    }
    

    You can check it out on github at https://github.com/nsagora/bundle-info-versioning.

提交回复
热议问题