구글 애드몹에 로그인하니 GDPR 메시지를 올해까지 구현하라고 상단에 알림이 떠서 구현하게 되었다.
애드몹 개인정보보호 페이지에가서 GDPR 메시지를 만들고
SwiftUI 프로젝트에 가서 앱이름App파일 부분에 이렇게 추가해주면 된다.
import SwiftUI
import UserMessagingPlatform
@main
struct AppnameApp: App {
init() {
let parameters = UMPRequestParameters()
parameters.tagForUnderAgeOfConsent = false
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) { [self] error in
if error != nil {
// Handle the error.
} else {
// The consent information state was updated.
// You are now ready to check if a form is
// available.
let formStatus = UMPConsentInformation.sharedInstance.formStatus
if formStatus == UMPFormStatus.available {
loadForm()
}
}
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
func loadForm() {
UMPConsentForm.load { form, loadError in
if loadError != nil {
// Handle the error.
} else {
// Present the form. You can also hold on to the reference to present
// later.
var viewController = UIViewController()
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let rootViewController = windowScene.windows.first?.rootViewController {
viewController = rootViewController
}
if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
form?.present(
from: viewController,
completionHandler: { dismissError in
if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained {
// App can start requesting ads.
}
// Handle dismissal by reloading form.
loadForm();
})
} else {
// Keep the form available for changes to user consent.
}
}
}
}
}