SHBerooz 0.1.0

SHBerooz 0.1.0

Shahin Katebi 维护。



SHBerooz 0.1.0

  • shaahin

SHBerooz

CI Status Version License Platform

做什么?

SHBerooz 使得检查更新并通知用户关于应用新版本的更容易。它还包含强制更新模式,阻止用户在没有更新当前应用的情况下继续。更新检查是基于自定义的定期进行,并且是自动管理的。

示例

要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install

安装

SHBerooz 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中

pod 'SHBerooz'

配置

创建您的自定义配置,并在使用 SHBerooz 之前将其设置为 SHBerooz 共享实例默认配置在您的 AppDelegate 或其他位置。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        
        // Configuring SHBerooz
        var config = BeroozConfigurations()
        config.updateUrl = URL(string: "https://api.seeb.co/apps/shberooz/example.json")
        // Title for presenting alert controller.
        config.alertTitle = "SHBerooz"
        // Retry button title
        config.retryButtonTitle = "Retry"
        // Update button title
        config.updateButtonTitle = "Update"
        // Cancel button title
        config.cancelButtonTitle = "Cancel"
        // Connection error alert message
        config.connectionErrorMessage = "Cannot receive update information :/"
        // Update check frequency, in days
        config.checkForUpdateFrequency = 7
        
        // set default configurations
        SHBerooz.shared.config = config
        
        return true
    }

然后在 SHBerooz 共享实例上使用函数 checkForUpdates 检查更新。然后使用具有 UpdateCheckStatus 枚举的完成处理程序接收处理结果。

SHBerooz.shared.checkForUpdates(withAlert: true) { (result) in
                var canProceed = false
             switch(result)
             {
                    
                case .wrongConfigs:
                    print("config error")
                    break
                case .updateCheckNotNeeded:
                    canProceed = true
                    break
                case .appVersionIsCurrent:
                    canProceed = true
                    break
                case .failedToCheck(let error):
                    print("Connection error :( \(String.init(describing: error))")
                    break
                case .failedToParse(let error):
                    print("Parsing error :( \(String.init(describing: error))")
                    break
                case .newVersionAvailable(let updateObject, let proceed):
                    canProceed = proceed
                    break
                
                }
                
                // now we proceed if the app is updated OR the needed update is not forced.
                if canProceed {
                    // Your app can proceed.
                }else {
                    // Show some errors.
                }
            }
        }

作者

Shahin Katebi, [email protected]

https://www.linkedin.com/in/katebi/

许可协议

SHBerooz 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。