iOS 安装向导
如何安装
CocoaPods
我们强烈推荐使用 CocoaPods 来安装我们的 SDK。在您的 Podfile
中,为您的应用程序目标添加以下行:
pod 'CCPAConsentViewController', '1.5.0'
Carthage
我们还支持 Carthage。安装需要更多步骤,我们专为它提供了一个专门的 维基页面。如果遗漏了任何步骤,请告诉我们。
手册
我们还支持SDK的手动集成。这需要更多的步骤来安装,所以我们专门为它创建了一个Wiki页面。如果遗漏了任何步骤,请告诉我们。
如何使用它
非常简单,以下为您提供了5个简单步骤
- 实现
ConsentDelegate
协议 - 使用您的Account ID、属性ID、属性名称、隐私管理器ID、活动环境和同意代表来实例化
CCPAConsentViewController
- 当您的应用启动时调用
.loadMessage()
,或在您希望显示隐私管理器时调用.loadPrivacyManager()
- 在消息/PM准备好显示时显示控制器
- 盈利!
Swift
import CCPAConsentViewController
class ViewController: UIViewController {
lazy var consentViewController: CCPAConsentViewController = { return CCPAConsentViewController(
accountId: 22,
propertyId: 6099,
propertyName: try! PropertyName("ccpa.mobile.demo"),
PMId: "5df9105bcf42027ce707bb43",
campaignEnv: .Public,
consentDelegate: self
)}()
@IBAction func onPrivacySettingsTap(_ sender: Any) {
consentViewController.loadPrivacyManager()
}
override func viewDidLoad() {
super.viewDidLoad()
consentViewController.loadMessage()
}
}
extension ViewController: ConsentDelegate {
func ccpaConsentUIWillShow() {
present(consentViewController, animated: true, completion: nil)
}
func consentUIDidDisappear() {
dismiss(animated: true, completion: nil)
}
func onAction(_ action: Action, consents: PMConsents?) {
print("Action taken:", action)
}
func onConsentReady(consentUUID: ConsentUUID, userConsent: UserConsent) {
print("consentUUID:", consentUUID)
print("userConsents:", userConsent)
print("CCPA applies:", UserDefaults.standard.bool(forKey: CCPAConsentViewController.CCPA_APPLIES_KEY))
// the us privacy string can also be accessed via userConsent.uspstring
print("US Privacy String:", UserDefaults.standard.string(forKey: CCPAConsentViewController.IAB_PRIVACY_STRING_KEY) ?? "")
}
<<<<<<< HEAD
func onError(error: CCPAConsentViewControllerError?) {
print("Error:", error.debugDescription)
=======
func onError(ccpaError: CCPAConsentViewControllerError?) {
logger.log("Error: %{public}@", [ccpaError?.description ?? "Something Went Wrong"])
>>>>>>> develop
}
}
Objective-C
#import "ViewController.h"
@import CCPAConsentViewController;
@interface ViewController ()<ConsentDelegate> {
CCPAConsentViewController *ccpa;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
PropertyName *propertyName = [[PropertyName alloc] init:@"ccpa.mobile.demo" error:NULL];
ccpa = [[CCPAConsentViewController alloc]
initWithAccountId:22
propertyId:6099
propertyName:propertyName
PMId:@"5df9105bcf42027ce707bb43"
campaignEnv:CampaignEnvPublic
consentDelegate:self];
[ccpa loadMessage];
}
- (void)consentUIWillShow {
[self presentViewController:ccpa animated:true completion:NULL];
}
- (void)consentUIDidDisappear {
[self dismissViewControllerAnimated:true completion:nil];
}
- (void)onConsentReadyWithConsentUUID:(NSString *)consentUUID userConsent:(UserConsent *)userConsent {
NSLog(@"ConsentUUID: %@", consentUUID);
NSLog(@"US Privacy String: %@", userConsent.uspstring);
NSLog(@"Consent status: %ld", (long)userConsent.status);
for (id vendorId in userConsent.rejectedVendors) {
NSLog(@"Rejected to Vendor(id: %@)", vendorId);
}
for (id purposeId in userConsent.rejectedCategories) {
NSLog(@"Rejected to Purpose(id: %@)", purposeId);
}
}
- (void)onErrorWithCcpaError:(CCPAConsentViewControllerError *)ccpaError {
NSLog(@"Something went wrong: %@", ccpaError);
}
@end
认证同意
工作原理
您需要给我们提供一个authId
,这可以是任何可以唯一标识您用户群中用户的标识,例如用户名、电子邮件、uuid。
我们将检查数据库以找到与该authId
关联的同意配置文件。如果我们找到了,我们会将其带到用户的设备上,并且不再显示同意消息(技术上这取决于我们在仪表板中设置的情景)如果我们没有找到与该authId
关联的任何同意配置文件,我们将创建一个并与其当前用户关联。
如何使用它?
使用认证同意的工作流程与上面提到的工作流程完全相同,但不是调用
consentViewController.loadMessage()
你应该使用
consentViewController.loadMessage(forAuthId: String?)
pubData
当用户在同意UI中采取行动时,可以将任意载荷附加到操作数据并将其发送到我们的端点。有关如何进行操作的更多信息,请查看我们的wiki:[发送用户采取操作时的任意数据](https://github.com/SourcePointUSA/CCPA_iOS_SDK/wiki/Sending-arbitrary-data-when-the-user-takes-an-action)