AxeptioSDK
用户同意不仅限于网页,还适用于所有收集用户数据的应用平台,包括移动设备。
作者
Axeptio
许可证
AxeptioSDK在MIT许可下可用。有关更多信息,请参阅LICENSE文件。
变更日志
0.5 (iOS 12+)
- Swift包管理器集成
安装
Swift包管理器
- 文件 > 添加包…
- 添加https://github.com/axeptio/axeptio-ios-sdk.git
- 选择“更新至下一个主要版本”并设置为“0.5.0”
CocoaPods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!
target 'MyApp' do
pod 'AxeptioSDK', '~> 0.5.0'
end
入门
Swift
在您的应用程序主控制器中,导入AxeptioSDK
模块,通过调用提供clientId
和version
的initialize
方法来初始化SDK。初始化完成后,您可以通过调用showConsentController
方法来显示小部件。
import UIKit
import AxeptioSDK
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Set a custom token
// Axeptio.shared.token = "auto-generated-token-xxx"
Axeptio.shared.initialize(clientId: "<Client ID>", version: "<Version>") { error in
// Handle error
// You could try to initialize again after some delay for example
Axeptio.shared.showConsentController(in: self) { error in
// User has made his choices
// We can now enable or disable the collection of metrics of the analytics library
if Axeptio.shared.getUserConsent(forVendor: "<Vendor name>") ?? false {
// Disable collection
} else {
// Enable collection
}
}
}
}
}
如果您的应用程序支持多种语言,您可能已经在Axeptio 管理网页为每个语言创建了不同的版本。在这种情况下,您可以在Localizable.strings
文件中存储每种语言的版本,并使用NSLocalizedString
获取用户相应的版本。
Objective-C
#import "ViewController.h"
#import <AxeptioSDK/AxeptioSDK-Swift.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Set a custom token
// [Axeptio setToken:@"auto-generated-token-xxx"];
[Axeptio initializeWithClientId:@"<Client ID>" version:@"<Version>" completionHandler:^(NSError *error) {
// Handle error
// You could try to initialize again after some delay for example
[Axeptio showConsentControllerWithInitialStepIndex:0 onlyFirstTime:TRUE in:self animated:YES completionHandler:^(NSError *error) {
// User has made his choices
// We can now enable or disable the collection of metrics of the analytics library
if ([Axeptio getUserConsentForVendor:@"<Vendor name>"]) {
// Disable collection
} else {
// Enable collection
}
}];
}];
}
@end
API参考
苹果跟踪用户数据许可
属性
token
使用token
属性可以设置自定义token。默认情况下,设置了随机标识符。
此属性特别适用于使用webview的应用程序。通过在axeptio_token
查询字符串参数中传递token打开webview,如果网站使用web SDK,则将在该网站上重复使用在应用程序中给出的同意。
方法
initialize
initialize
函数通过获取配置并在完成时调用完成处理程序来初始化SDK。
如果失败,例如由于网络问题,可以再次调用initialize
函数,除非错误是已初始化。
如果您需要为不同的项目ID重置Axeptio SDK,但对于相同的客户端ID,应调用revere函数或更改二者中的一个。
func initialize(clientId: String, version: String, completionHandler: @escaping (Error?) -> Void)
showConsentController
showConsentController
函数在一个给定的视图控制器中向用户显示Axeptio小部件,并在用户做出选择时调用完成处理程序。如果onlyFirstTime
为true,且用户在前一个调用中已经做出了选择,则不会显示小部件,并立即调用完成。但是,如果配置包括新的提供商,则再次显示小部件。您可以通过指定大于0的initialStepIndex
来显示不同的步骤。
func showConsentController(initialStepIndex: Int = 0, onlyFirstTime: Bool = true, in viewController: UIViewController, animated: Bool = true, completionHandler: @escaping (Error?) -> Void) -> (() -> Void)?
如果显示小部件,该函数返回一个reject处理程序,您可以调用它来隐藏小部件(如果需要)。否则,它返回nil。
getUserConsent
函数 getUserConsent
返回一个可选的布尔值,表示用户是否为其选择的供应商做出了选择以及是否给予了同意。如果返回的值是 nil
,则意味着供应商未出现在配置中或小部件尚未向用户显示。
func getUserConsent(forVendor name: String) -> Bool?
setUserConsentToDisagreeWithAll
函数 setUserConsentToDisagreeWithAll
将所有供应商的同意设置为“否”并保存偏好设置。当使用应用程序跟踪透明度功能时,此函数很有用。如果用户拒绝跟踪权限请求,请调用此函数以使 CMP 不显示并将用户的同意保存到 Axesio 同意日志中。