ユーザー同意¶
ヒューマンスコアリングユースケースの一部です。
SDK はユーザーがアプリをどのように操作するかを記録するため、デフォルトではユーザーが同意するまで 何も記録しません。SDK には SwiftUI と UIKit 向けの既成の同意アラートが用意されており、この保証を 失うことなく独自の UI に置き換えることもできます。
使いどころ¶
- 常に。ただし、アプリが
DeaSdkの作成前にすでに同意を得ている場合は除きます。その場合はrequireConsent: falseを設定してください - アラートの文言を変える、または翻訳するとき
- 設定画面からユーザーが同意を撤回できるようにするとき
前提条件¶
- SDK がインストールされ、開始されている。クイックスタートを参照してください。
- SwiftUI のアラートには iOS 15 以降が必要です。UIKit のアラートは iOS 13 から動作します。
使い方¶
組み込みのアラートを表示する(UIKit)¶
import DeaSDK
import UIKit
class HomeViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Dea.sdk?.requestConsent(from: self) { agreed in
print("DEA consent: \(agreed)")
}
}
}
- 回答は端末に保存されます。ユーザーが一度回答すると、以降の呼び出しは保存された回答で
completionを すぐに呼び出し、何も表示しないため、起動ごとに呼び出しても安全です。 - アラートには 2 つのボタンがあり、どちらも回答です。外側をタップして閉じることはできません。
組み込みのアラートを表示する(SwiftUI)¶
import DeaBase
import DeaSDK
import SwiftUI
struct HomeView: View {
@State private var askingConsent = false
var body: some View {
let content = Text("Home")
.onAppear {
if let dea = Dea.sdk, !dea.consent.isAnswered {
askingConsent = true
}
}
if let dea = Dea.sdk {
content.deaConsent(dea.consent, asking: $askingConsent) { agreed in
print("DEA consent: \(agreed)")
}
} else {
content
}
}
}
deaConsent モディファイアは asking が true になるたびにアラートを表示し、保存された回答を自分では
確認しません。上のように consent.isAnswered が false のときだけ asking を設定してください。
そうしないと、起動ごとにユーザーに尋ねることになります。
文言を変える¶
import DeaSDK
let copy = ConsentCopy(
title: "Help us keep bots out",
body: "We measure how you interact with the app to tell people apart from bots.",
recorded: ["Where you touch, and how hard", "How the phone moves in your hand"],
notRecorded: ["What you type", "What's on your screen"],
closing: "You can change this at any time in Settings.",
accept: "Allow",
decline: "Not now"
)
// UIKit
Dea.sdk?.requestConsent(from: self, copy: copy) { _ in }
// SwiftUI
// content.deaConsent(dea.consent, asking: $askingConsent, copy: copy) { _ in }
recorded または notRecorded に空の配列を渡すと、そのセクションは非表示になります。リストの内容が
アプリにとって正しいままであるようにしてください。
独自の UI を使う¶
独自の画面やオンボーディングのステップを描画し、回答を記録します。
import DeaSDK
Dea.sdk?.setConsent(true) // the user agreed
Dea.sdk?.setConsent(false) // the user declined
setConsent が返るとすぐに記録が開始または停止します。
現在の回答を読み取る¶
import DeaBase
import DeaSDK
if let consent = Dea.sdk?.consent {
print(consent.isAnswered) // false until the user has answered
print(consent.isGranted) // true only if the user agreed
print(consent.decision) // unknown, granted or denied
}
回答の変更を通知される¶
import DeaBase
import DeaSDK
let stopListening = Dea.sdk?.consent.onChange { decision in
print("DEA consent is now \(decision)")
}
// Later, to stop being notified:
stopListening?()
同意を撤回する¶
記録はすぐに停止します。セッションは保持されるため、ユーザーが再び同意すると、同じセッションで記録が 続きます。
再度求める¶
forget() は保存された回答を消去するため、次の requestConsent の呼び出し(または isAnswered の
確認)で再度尋ねることになります。たとえば、同じ端末で別のアカウントがサインインしたときです。拒否とは
異なり、これは回答ではありません。
共有端末¶
セッションごとに別の人が端末を使う可能性がある場合(キオスク、テスト端末)、回答を保存しないでください。
// UIKit
Dea.sdk?.requestConsent(from: self, remember: false) { _ in }
// SwiftUI
// content.deaConsent(dea.consent, asking: $askingConsent, remember: false) { _ in }
// Your own UI
Dea.sdk?.setConsent(true, remember: false)
remember: false では UIKit のアラートは呼び出しごとに表示され、回答はこの実行中だけ保持されます。
例¶
設定のスイッチ(SwiftUI)¶
import DeaBase
import DeaSDK
import SwiftUI
struct DeaConsentToggle: View {
@State private var granted = Dea.sdk?.consent.isGranted ?? false
var body: some View {
Toggle("Bot protection", isOn: $granted)
.disabled(Dea.sdk == nil)
.onChange(of: granted) { value in
Dea.sdk?.setConsent(value)
}
}
}
設定のスイッチ(UIKit)¶
import DeaBase
import DeaSDK
import UIKit
class PrivacySettingsViewController: UIViewController {
private let toggle = UISwitch()
override func viewDidLoad() {
super.viewDidLoad()
toggle.isOn = Dea.sdk?.consent.isGranted ?? false
toggle.isEnabled = Dea.sdk != nil
toggle.addTarget(self, action: #selector(toggled), for: .valueChanged)
view.addSubview(toggle)
}
@objc private func toggled() {
Dea.sdk?.setConsent(toggle.isOn)
}
}
API¶
| メンバー | 戻り値 | 説明 |
|---|---|---|
DeaSdk.requestConsent(from:copy:remember:completion:) |
Void |
UIKit。必要ならアラートを表示し、回答で completion を呼び出す |
View.deaConsent(_:asking:copy:remember:onAnswer:) |
some View |
SwiftUI、iOS 15 以降。asking が true の間アラートを表示し、回答を記録する |
DeaSdk.setConsent(_:remember:) |
Void |
回答を記録する |
DeaSdk.consent |
Consent |
現在の回答 |
Consent.isAnswered |
Bool |
ユーザーが回答したかどうか |
Consent.isGranted |
Bool |
ユーザーが同意したかどうか |
Consent.decision |
ConsentDecision |
.unknown、.granted、.denied のいずれか |
Consent.forget() |
Void |
保存された回答を消去する |
Consent.onChange(_:) |
() -> Void |
回答が変わるとリスナーを呼び出す。返されたクロージャを呼ぶと停止する |
関連¶
- オプション:
requireConsent - オプション:
consent— 回答を独自のストレージに保持する - 機密性の高い画面
- API リファレンス