AppGuard 0.3.0

AppGuard 0.3.0

Bill350Guillaume BonninAmaury DAVIDGuillaume Chieb bouares 维护。



AppGuard 0.3.0

💂‍♀️AppGuard

CI Status Version License Platform

AppGuard 是一个 iOS 应用的守护程序💂‍♀️用于检查/强制用户更新您的应用或显示已更改的内容。

要求

  • iOS 9.0+
  • Swift 4.2+
  • Xcode 10.0+

示例

要运行示例项目,请克隆仓库,然后从示例目录运行 pod install

安装

StarsKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中即可。

pod 'AppGuard'

第三方依赖

当今我们有一些第三方依赖项,但目的是尽可能避免它们。

我们还想快速获得库和极具可定制的库,因此我们使用一个依赖项

  • Jelly:用于简化评分过渡显示的简单 UI 组件

描述 & 特性

AppGuard为您提供三种默认行为来

  1. 检查并向用户显示是否需要下载您应用程序的新版本(强制更新)。
  2. 检查并向用户显示是否应该下载您应用程序的新版本(推荐更新)。
  3. 向用户显示最新版本中的新功能(更新信息)。

通过复活显示机制、阻断或可 dismissable 弹窗,用户将/可能需要根据显示的信息和操作更新您的应用程序。

特性列表

  • 静态配置字符串
  • Cocoapods集成
  • 默认 & 可配置步骤过渡
  • 默认显示算法行为
  • 自定义字体、文本 & 颜色
  • 屏幕动作回调
  • 可使用字典/数据或远程URL配置:一切皆有可能!
  • 可覆盖布局
  • 生命周期显示事件([will/did]出现/消失)
  • 配置解析键
  • 将远程配置绑定到StarsKit数据的Firebase扩展
  • 在默认检查上进行额外条件检查
  • Carthage集成
  • 使用本地化或配置字符串
  • 默认本地化字符串
    • 英文
    • 法语
  • 可覆盖本地化字符串
  • 自定义显示算法行为

默认用法

初始化应用守护者

// Simply use the prepare method for default configuration properties
AppGuard.default.prepare()

// Configure the dataSource
AppGuard.default.dataSource = self

// And optionnaly the uiDelegate
AppGuard.default.uiDelegate = self

实现数据源

这很有必要来实现它,以指示演示者控制器到 AppGuard,并且可选地与 UIImageView 做一些事情。

// MARK: - AppGuardDataSource
extension ViewController: AppGuardDataSource {
  func configureImageView(_ imageView: UIImageView?) {
    
	// Do anything with the UIImageView, 
	// 1- Download an Image with Kingfisher
	// 2- Add a Lottie animated subview on it
    
  }
  
  func guardPresenterController() -> UIViewController? {
    return self
  }
  
}

实现 UI 代理

UI 代理将发送生命周期和用户交互事件给您。

强烈建议实现 didChooseLater:didChooseAction:

// MARK: - AppGuardUIDelegate
extension ViewController: AppGuardUIDelegate {
  func guardControllerWillAppear(for context: AppGuardContextType) {
    print("guardControllerWillAppear")
  }
  
  func guardControllerDidAppear(for context: AppGuardContextType) {
    print("guardControllerDidAppear")
  }
  
  func guardControllerWillDisappear(for context: AppGuardContextType) {
    print("guardControllerWillDisappear")
  }
  
  func guardControllerDidDisappear(for context: AppGuardContextType) {
    print("guardControllerDidDisappear")
  }
  
  func didChooseLater(for context: AppGuardContextType) {
    print("didChooseLater")
  }
  
  func didChooseAction(for context: AppGuardContextType) {
    if context == .mandatoryUpdate || context == .recommandedUpdate {
      UIApplication.shared.openURL(URL(string: "https://itunes.apple.com/fr/app/<your app ID>")!)
    }
  }
  
}

更新 AppGuard 配置

AppGuard 使用简单的字典数据来更新其配置。

let configurationData // a [String: Any?] instance from JSON file or static dictionnary or anything else
AppGuard.default.updateConfig(from: configurationData)

// Ask the guard 💂‍♀️ if we can pass 
AppGuard.default.displayUpdateStatus()

// You can force it too 💂‍♀️🤷‍♂️
AppGuard.default.displayUpdateStatus(forced: true)

自定义键绑定

ℹ️您可以使用 AppGuardConfigurationKeysBinder 选定指定键绑定,将源配置绑定到 AppGuard 配置。默认情况下,将使用 AppGuardConfigurationKeys 的 rawValues。

假设您有一个如下的自定义 JSON 结构

{
  "my_deeplink_key": "http://www.google.custom",
  "my_dialog_type_key": 1,
  "my_content_key": "Custom content text",
  "my_action_label_key": "Custom action label",
  "my_changelog_content_key": "Custom changelog text",
  "my_title_key": "Custom title",
  "my_imageurl_key": "Custom image URL",
  "my_laterButtonLabel_key": "Later",
  "my_maxDaysBetweenDisplay_key": 3,
  "my_versionCode_key": 2
}

使用 AppGuardConfigurationKeysBinder 修改默认键绑定

let binding: [String: String?] = [AppGuardConfigurationKeys.deeplink.rawValue: "my_deeplink_key",
                                      AppGuardConfigurationKeys.dialogType.rawValue: "my_dialog_type_key",
                                      AppGuardConfigurationKeys.content.rawValue: "my_content_key",
                                      AppGuardConfigurationKeys.actionButtonLabel.rawValue: "my_action_label_key",
                                      AppGuardConfigurationKeys.changelogContent.rawValue: "my_changelog_content_key",
                                      AppGuardConfigurationKeys.title.rawValue: "my_title_key",
                                      AppGuardConfigurationKeys.imageUrl.rawValue: "my_imageurl_key",
                                      AppGuardConfigurationKeys.versionCode.rawValue: "my_versionCode_key"]

AppGuardConfigurationKeysBinder.bindConfigurationKeys(binding)

自定义

用户内容查看控制器定制

您可以简单地覆盖默认控制器的 .xib 名称。

  • AppGuardChangelogViewController
  • AppGuardUpdateViewController

例如,创建一个设置 StarsKit 模块为拥有者的 AppGuardChangelogViewController.xib 文件。IB_OUTLETS 是可选的,因此您可以选择要覆盖什么或不覆盖什么。

记得 IBAction 链接!

注意:即将提供对 UIViewController 自定义类的支持。

UI 定制 - AppGuardGraphicContext

您可以将 AppGuardGraphicContext 设置为您自己的值。

AppGuard.default.graphicContext.actionButtonBackgroundColor = UIColor.ex.fromHexa("#17b8c5")
AppGuard.default.graphicContext.jellyCustomTransition = myCustomJellyPresentation
AppGuard.default.graphicContext.buttonCornerRadius = 5

可自定义的属性为

  • cornerRadius: CGFloat
  • roundedButton: Bool
  • actionButtonBackgroundColor: UIColor?
  • actionButtonTitleColor: UIColor
  • actionButtonFont: UIFont
  • laterButtonBackgroundColor: UIColor?
  • laterButtonTitleColor: UIColor
  • laterButtonFont: UIFont
  • titleFont: UIFont
  • titleColor: UIColor
  • contentFont: UIFont
  • contentColor: UIColor
  • image: UIImage?
  • jellyCustomTransition: JellyPresentation

过渡和显示(水母状效果)

AppGuard 使用水母状效果进行可自定义的过渡。您可以通过 AppGuardGraphicContext 中的 jellyCustomTransition 属性指定自己的效果。

更多关于 Jelly 存储库 的信息。

字符串定制(即将推出)

您可以使用配置字符串或本地izable字符串,您可以在您的应用程序包中覆盖这些字符串。

使用 Firebase 远程配置

如果你的应用已经使用Firebase,为什么不使用

Firebase Remote Config功能呢?AppGuard将能够将你关联的Firebase远程配置对象转换为自读数据字典

👌.

安装

添加Firebase Podspec

pod 'AppGuard/FirebaseRemoteConfig'
// Bind the properties keys if needed before 
// or use the default ones in the remote config

let remoteConfig = RemoteConfig.remoteConfig()
remoteConfig.fetch(withExpirationDuration: 1.second) { (status, _) in
	remoteConfig.activateFetched()
	AppGuard.default.updateConfig(from: remoteConfig)
	AppGuard.default.checkUpdateStatus()
}

贡献者

制作于🇫🇷由Smart&Soft的iOS团队。

许可证

AppGuard采用MIT许可证。有关更多信息,请参阅LICENSE文件。