App-Notice-IAB 版本 1.1.1

App-Notice-IAB 1.1.1

Will BroadheadJake ODowdJeff Wheeler 维护。



App-Notice SDK for iOS (IAB 版本)
安装和自定义

版本:1.1.1
2018年10月31日

WIP ReadMe

Version License Platform

特性

  • 隐式同意追踪
  • 显式同意追踪
  • 文本自定义和本地化
  • 用户跟踪切换
  • 数据访问请求

示例

此仓库包含两个示例项目以展示如何使用 SDK。'Triangle' 项目使用 Swift 编写,而 'Triangle-Objc' 使用 Objective-C 编写。这些项目位于 Example 文件夹中。

要运行 Triangle 项目,请克隆仓库,并从 Example/Triangle 目录执行 pod install。如果已经安装,请运行 pod update App-Notice-IAB

作者

Evidon

许可

App-Notice 遵循 MIT 许可协议。更多信息见 LICENSE 文件。

先决条件

  • iOS 8.0+
  • Xcode 7.0+
  • 从 Evidon 隐私控制面板获取有效的 App Notice ID。有关详细信息,请联系您的 Evidon 客户成功经理。

安装

请通过 CocoaPods 获取 App-Notice。要安装

将以下行添加到您的 Podfile 中,然后运行 'pod install' 并打开您的 xcworkspace 文件。

pod 'App-Notice-IAB'

如果您使用 Objective-C 项目使用 SDK,只需将以下行添加到使用该框架的任何文件中导入框架即可。如果您有一个 Swift 项目,您则需要将此行添加到您的桥接头文件中。(有关如何进行此操作的说明,请参阅下面的创建桥接头。)

#import <AppNoticeSDKFramework/AppNoticeSDKFramework.h>

为 Swift 项目创建桥接头

如果您的项目用 Swift 编写并且您还没有桥接头文件,最简单的方法是向项目添加新的 Objective-C 文件。Xcode 将会询问是否要配置 Objective-C 桥接头。选择“创建桥接头”,然后您可以删除刚刚创建的多余的 Objective-C 文件。

SDK 激活

在使用 SDK 功能之前,您必须先激活 SDK。您可以使用您的激活令牌来完成此操作。

请注意,SDK 跟踪列表仅下载一次,并存储在每个激活令牌的设备上。这意味着如果您在应用发布后更改跟踪列表,您需要创建一个新的带有不同激活令牌的应用通知。在这些更改出现之前,您需要更新 SDK 并重新发布您的应用。

Swift

AppNoticeSDK.sharedInstance().activateWithToken("bff0f04910354fb8a042650840056c9d")

Objective-C

[[AppNoticeSDK sharedInstance] activateWithToken:@"bff0f04910354fb8a042650840056c9d"];

用法

请求同意

存在两种类型的同意:暗示的显式的。暗示的是推荐(且更简单)的选项,但您可以根据调用的showConsentFlow SDK方法选择其中之一。为了完全遵守隐私法规,您应该尽量在应用启动后尽早请求用户的同意。如果您选择显式,则通知必须在触发任何跟踪技术之前显示。

从主视图控制器中的viewDidAppear方法调用showConsentFlow(或showExplicitConsentFlow)方法。这样,SDK就可以确定是否需要显示对话框。

暗示同意

默许同意本质上是仅披露选项。它告知用户,他通过继续使用应用程序自动给予同意,但也允许用户启用/禁用单个跟踪器。因此,它不包含 接受拒绝 选项,只有 继续。它还包括 repeatEvery30Days 参数,如果该参数为真,则每30天重新显示同意对话框。如果为假,则每条通知ID只会显示一次。

Swift
override func viewDidAppear(animated: Bool) {
  showPrivacyConsentFlow()
    
  super.viewDidAppear(animated)
}

func showPrivacyConsentFlow() {
  AppNoticeSDK.sharedInstance().showConsentFlowWithOnClose({ (result, trackers) in
    // TODO: Handle what you want to do based on whether the user accepted or declined consent.
    // You should also allow or block specific trackers/ads based on the 'trackers' array contents.
  }, presentingViewController:self, repeatEvery30Days:false)
}
Objective-C
- (void)viewDidAppear:(BOOL)animated {
  // show the privacy consent flow (if needed)
  [self showPrivacyConsentFlow];
    
  [super viewDidAppear:animated];
}

- (void)showPrivacyConsentFlow {
  [[AppNoticeSDK sharedInstance] showConsentFlowWithOnClose:^(AppNoticeConsent result, NSDictionary *trackers) {
    // TODO: Handle what you want to do based on whether the user accepted or declined consent.
    // You should also allow or block specific trackers/ads based on the 'trackers' array contents.
  } presentingViewController:self repeatEvery30Days:NO];
}

明确同意

用户必须接受或拒绝明确同意。如果被接受,应用程序可以正常运行。但是,如果被拒绝,需要处理几种情况。

Swift
override func viewDidAppear(animated: Bool) {
  showPrivacyConsentFlow()
    
  super.viewDidAppear(animated)
}

func showPrivacyConsentFlow() {
  AppNoticeSDK.sharedInstance().showExplicitConsentFlowWithOnClose({ (result, trackers) in
    // TODO: Handle what you want to do based on whether the user accepted or declined consent.
    // You should also allow or block specific trackers/ads based on the 'trackers' array contents.
    }, presentingViewController: self)
}
Objective-C
- (void)viewDidAppear:(BOOL)animated {
  // show the privacy consent flow (if needed)
  [self showPrivacyConsentFlow];
    
  [super viewDidAppear:animated];
}

- (void)showPrivacyConsentFlow {
  [[AppNoticeSDK sharedInstance] showExplicitConsentFlowWithOnClose:^(AppNoticeConsent result, NSDictionary *trackers) {
    // TODO: Handle what you want to do based on whether the user accepted or declined consent.
    // You should also allow or block specific trackers/ads based on the 'trackers' array contents.
  } presentingViewController:self];
}

跟踪首选项

用户可以开启或关闭跟踪器。要显示跟踪首选项屏幕

Swift
AppNoticeSDK.sharedInstance().showManagePreferences { () -> Void in
    // TODO: Handle what you want to do after the preferences screen is closed.
            
    // Get the newly updated tracker preferences
    if let updatedTrackers = AppNoticeSDK.sharedInstance().getTrackerPreferences() as? Dictionary<String, NSNumber> {
        // TODO: Do something with the updated trackers
    }
}
Objective-C
[[AppNoticeSDK sharedInstance]showManagePreferences:^{
// TODO: Handle what you want to do after the preferences screen is closed.

//Get the newly updated tracker preferences
NSDictionary *updatedTrackers = [[AppNoticeSDK sharedInstance] getTrackerPreferences];

}];

本地化和文本定制

AppNotice SDK可以支持多种语言(目前只有英语,但法语、意大利语、荷兰语、德语、西班牙语和葡萄牙语将很快可用)。如果您的应用程序支持受支持的语言的本地化,AppNotice SDK也将显示在该语言中。要本地化您的应用程序,您只需在每个受支持的语言中为您的项目准备一个本地化文件。有关如何将本地化添加到您的应用程序的详细信息,请见Apple的文档

要自定义SDK中显示的任何字符串

  1. 为所需语言将本地化文件添加到您的项目中(如果尚未添加)。
  2. 查找您想自定义的字符串的关键字。您可以在SDK的AppNotice.bundle中的Localizable.strings文件中找到它。
  3. 将关键字复制到您自己的应用程序中要自定义的语言的Localizable.strings文件。
  4. 将新添加的字符串的值(而不是关键字)设置为要显示的文本。

例如,要自定义这里的SDK AppNotice Bundle中显示的en.lproj的ghostery_dialog_implicit_message属性,请复制此处显示的密钥

将它们粘贴到项目的 Localizable.strings 文件中,并以所需文本作为值:

如果您想要为其他语言应用相同的更改,只需更新相应 Localizable.strings 文件中的相同 ghostery_dialog_implicit_message 属性(英语:en.lproj/Localizable.strings,德语:de.lproj/Localizable.strings,西班牙语:es.lproj/Localizable.strings 等)。

用户界面定制

也许您想定制 AppNotice 视图的外观和感觉以匹配您应用程序的主题。如果只需要从默认的浅色主题改为深色主题,只需设置 AppNoticeSDK 上的 appTheme 属性

AppNoticeSDK.sharedInstance().appTheme = AppNoticeThemeDark
[AppNoticeSDK sharedInstance].appTheme = AppNoticeThemeDark;

对于更详细的定制,以下 AppNoticeSDK UIColor 属性可用

  • mainTextColor:SDK 中文本的颜色。
  • backgroundColor:所有视图的背景颜色。
  • acceptButtonColor:接受/继续按钮的色调/背景颜色。
  • acceptButtonTextColor:接受/继续按钮的文本颜色。
  • declineButtonColor:拒绝按钮的颜色。
  • navBarBackgroundColor:导航条的背景颜色。
  • navBarTitleColor:导航条中心标题文本的颜色。
  • tintColor:色调颜色应用于复选框、设置按钮以及导航栏中的后退/前进按钮。
  • disabledColor:禁用状态下复选框的颜色(用于基本标签)。
  • separatorColor:水平和垂直分隔符的颜色以及偏好设置表视图单元格的选择颜色。

支持多个应用程序版本

要支持含有不同追踪器的多个应用程序版本,为每个版本的每个应用程序使用唯一的 App Notice 配置。使用 Ghostery 控制面板(https://my.ghosteryenterprise.com)为具有不同追踪器组合的不同应用程序版本创建 App Notice 配置。

创建 App Notice 后,确保在如下所述初始化 SDK 时使用正确的 App Notice ID。