시작하기

Google 사용자 메시지 플랫폼 (UMP) SDK는 개인 정보 보호 선택사항을 관리하는 데 도움이 됩니다 자세한 내용은 개인정보 보호 및 메시지를 사용하세요.

메시지 유형 만들기

다음 중 하나로 사용자 메시지를 작성합니다. 사용 가능한 사용자 메시지 유형 Privacy & 메시지 탭에서 애드 관리자 있습니다. UMP SDK는 애플리케이션 ID에서 생성된 Ad Manager 개인 정보 보호 메시지 확인할 수 있습니다

자세한 내용은 개인 정보 보호 및 메시지 정보

SDK 가져오기

CocoaPods (권장)

SDK를 iOS 프로젝트로 가져오는 가장 쉬운 방법은 CocoaPods 프로젝트의 Podfile에서 파일을 가져오고 다음 행을 앱의 타겟에 추가합니다.

pod 'GoogleUserMessagingPlatform'

그런 후 다음 명령어를 실행하세요.

pod install --repo-update

CocoaPods를 처음 사용하는 경우 CocoaPods를 참조하세요. 사용할 수 있습니다

Swift Package Manager

UMP SDK는 Swift Package Manager도 지원합니다. 다음 단계를 따르세요. Swift 패키지를 가져옵니다.

  1. Xcode에서 파일 > 패키지 추가...를 클릭합니다.

  2. 메시지가 표시되면 UMP SDK Swift Package GitHub를 검색합니다. 저장소:

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. 사용할 UMP SDK Swift 패키지의 버전을 선택합니다. 신규 Up to Next Major Version(최대 다음 메이저 버전)을 사용하는 것이 좋습니다.

그런 다음 Xcode가 패키지 종속 항목을 확인하고 있습니다. 패키지 종속 항목을 추가하는 방법에 대한 자세한 내용은 Apple의 도움말을 참조하세요.

수동 다운로드

SDK를 가져오는 다른 방법은 수동으로 가져오는 것입니다.

SDK 다운로드

그런 다음, 프레임워크를 Xcode 프로젝트로 드래그하여 Copy(복사)’를 선택합니다. 상품 추가를 요청할 수 있습니다.

그런 다음, 다음을 사용하여 필요한 모든 파일에 프레임워크를 포함할 수 있습니다.

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

애플리케이션 ID 추가

다음에서 애플리케이션 ID를 찾을 수 있습니다. Ad Manager UI. ID를 Info.plist 다음 코드 스니펫으로 대체합니다.

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>

모든 앱에서 사용자 동의 정보 업데이트를 요청해야 합니다. requestConsentInfoUpdateWithParameters:completionHandler:를 사용하여 실행합니다. 이 요청은 다음과 같습니다.

  • 동의 필요 여부. 예를 들어 이전 동의 결정이 만료되었습니다.
  • 개인 정보 보호 옵션 진입점의 필요 여부. 일부 개인 정보 보호 메시지 사용자가 언제든지 개인 정보 보호 옵션을 수정하도록 앱에 요구할 수 있습니다.

다음은 UIViewController viewDidLoad() 메서드를 사용하여 지도 가장자리에 패딩을 추가할 수 있습니다.

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    // TODO: Load and present the privacy message form.
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            // TODO: Load and present the privacy message form.
          }];
}

필요한 경우 개인 정보 보호 메시지 양식 로드 및 표시

최신 동의 상태를 받은 후 loadAndPresentIfRequiredFromViewController:completionHandler: 사용자 동의를 수집할 수 있습니다. 로드되면 양식이 즉시 표시됩니다.

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      [weak self] loadAndPresentError in
      guard let self else { return }

      if let consentError = loadAndPresentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      // Consent has been gathered.
    }
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                }];
          }];
}

사용자가 결정을 내렸거나 닫은 후 작업을 실행해야 하는 경우 completion handler에 로직을 배치합니다. 선택합니다.

공개 설정 옵션

일부 개인 정보 보호 메시지 양식은 게시자가 렌더링한 개인 정보 보호에서 제공됩니다. 옵션 진입점을 사용하여 사용자가 언제든지 개인 정보 보호 옵션을 관리할 수 있습니다. 개인 정보 보호 옵션에서 사용자에게 표시되는 메시지를 자세히 알아보려면 진입점, 사용 가능한 사용자 메시지 유형

개인 정보 보호 옵션 진입점을 구현하려면 다음 단계를 완료하세요.

  1. UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus를 확인합니다.
  2. 개인 정보 보호 옵션 진입점이 필요한 경우 표시 및 상호작용 가능한 UI 요소를 앱에 추가합니다.
  3. 다음 명령어를 사용하여 개인 정보 보호 옵션 양식을 트리거합니다. presentPrivacyOptionsFormFromViewController:completionHandler:

다음 코드 예시는 이러한 단계를 보여줍니다.

Swift

@IBOutlet weak var privacySettingsButton: UIBarButtonItem!

var isPrivacyOptionsRequired: Bool {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == .required
}

override func viewDidLoad() {
  // ...

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    // ...

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      //...

      // Consent has been gathered.

      // Show the button if privacy options are required.
      self.privacySettingsButton.isEnabled = isPrivacyOptionsRequired
    }
  }
  // ...
}

// Present the privacy options form when a user interacts with the
// privacy settings button.
@IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) {
  UMPConsentForm.presentPrivacyOptionsForm(from: self) {
    [weak self] formError in
    guard let self, let formError else { return }

    // Handle the error.
  }
}

Objective-C

@interface ViewController ()
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;
@end

- (BOOL)isPrivacyOptionsRequired {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
         UMPPrivacyOptionsRequirementStatusRequired;
}

- (void)viewDidLoad {
  // ...

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            // ...

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  // ...

                  // Consent has been gathered.

                  // Show the button if privacy options are required.
                  strongSelf.privacySettingsButton.enabled = isPrivacyOptionsRequired;
                }];
          }];
}

// Present the privacy options form when a user interacts with your
// privacy settings button.
- (IBAction)privacySettingsTapped:(UIBarButtonItem *)sender {
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:self
                                completionHandler:^(NSError *_Nullable formError) {
                                  if (formError) {
                                    // Handle the error.
                                  }
                                }];
}

광고 요청

앱에서 광고를 요청하기 전에 동의를 얻었는지 확인하세요. UMPConsentInformation.sharedInstance.canRequestAds를 사용하여 사용자로부터 반환합니다. 두 가지 동의를 수집할 때 확인해야 할 곳은 다음과 같습니다.

  • 현재 세션에서 동의를 수집한 후
  • requestConsentInfoUpdateWithParameters:completionHandler:를 호출한 직후 이전 세션에서 동의를 받았을 수 있습니다. 지연 시간 콜백이 완료될 때까지 기다리지 않는 것이 좋습니다. 그래야 최대한 빨리 광고 로드를 시작하세요
를 호출할 때까지

동의 수집 과정에서 오류가 발생하더라도 광고를 요청할 수 없습니다. UMP SDK는 이전 세션입니다.

Swift

class ViewController: UIViewController {

  // Use a boolean to initialize the Google Mobile Ads SDK and load ads once.
  private var isMobileAdsStartCalled = false

  override func viewDidLoad() {
    super.viewDidLoad()

    // Request an update for the consent information.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
      [weak self] requestConsentError in
      guard let self else { return }

      if let consentError = requestConsentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      UMPConsentForm.loadAndPresentIfRequired(from: self) {
        [weak self] loadAndPresentError in
        guard let self else { return }

        if let consentError = loadAndPresentError {
          // Consent gathering failed.
          return print("Error: \(consentError.localizedDescription)")
        }

        // Consent has been gathered.
        if UMPConsentInformation.sharedInstance.canRequestAds {
          self.startGoogleMobileAdsSDK()
        }
      }
    }
    
    // Check if you can initialize the Google Mobile Ads SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if UMPConsentInformation.sharedInstance.canRequestAds {
      startGoogleMobileAdsSDK()
    }
  }
  
  private func startGoogleMobileAdsSDK() {
    DispatchQueue.main.async {
      guard !self.isMobileAdsStartCalled else { return }

      self.isMobileAdsStartCalled = true

      // Initialize the Google Mobile Ads SDK.
      GADMobileAds.sharedInstance().start()

      // TODO: Request an ad.
      // GADInterstitialAd.load(...)
    }
  }
}

Objective-C

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }
            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                  __strong __typeof__(self) strongSelf = weakSelf;
                  if (!strongSelf) {
                    return;
                  }

                  if (UMPConsentInformation.sharedInstance.canRequestAds) {
                    [strongSelf startGoogleMobileAdsSDK];
                  }
                }];
          }];

  // Check if you can initialize the Google Mobile Ads SDK in parallel
  // while checking for new consent information. Consent obtained in
  // the previous session can be used to request ads.
  if (UMPConsentInformation.sharedInstance.canRequestAds) {
    [self startGoogleMobileAdsSDK];
  }
}

- (void)startGoogleMobileAdsSDK {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    // Initialize the Google Mobile Ads SDK.
    [GADMobileAds.sharedInstance startWithCompletionHandler:nil];

    // TODO: Request an ad.
    // [GADInterstitialAd loadWithAdUnitID...];
  });
}

테스트

개발하는 동안 앱에서 통합을 테스트하려면 다음 단계에 따라 테스트 기기를 프로그래매틱 방식으로 등록하세요. 반드시 를 사용하는 것이 좋습니다.

  1. requestConsentInfoUpdateWithParameters:completionHandler:를 호출합니다.
  2. 로그 출력에서 다음 예와 비슷한 메시지를 확인합니다. 에 기기 ID와 테스트 기기로 추가하는 방법이 표시됩니다.

    <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
    
  3. 테스트 기기 ID를 클립보드에 복사합니다.

  4. 코드를 수정하여 전화 UMPDebugSettings().testDeviceIdentifiers 다음으로 전달합니다. 테스트 기기 ID 목록입니다.

    Swift

    let parameters = UMPRequestParameters()
    let debugSettings = UMPDebugSettings()
    debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
    parameters.debugSettings = debugSettings
    // Include the UMPRequestParameters in your consent request.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
        with: parameters,
        completionHandler: { error in
          ...
        })
    

    Objective-C

    UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
    UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
    debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
    parameters.debugSettings = debugSettings;
    // Include the UMPRequestParameters in your consent request.
    [UMPConsentInformation.sharedInstance
        requestConsentInfoUpdateWithParameters:parameters
                            completionHandler:^(NSError *_Nullable error){
                              ...
    }];
    

지역 강제 설정

UMP SDK는 마치 기기가 제대로 작동하지 않는 것처럼 앱 동작을 테스트하는 방법을 제공합니다. the debugGeography property of type UMPDebugGeography on UMPDebugSettings를 사용하여 EEA 또는 영국에 거주 참고: 디버그 설정은 테스트 기기에서만 작동합니다.

Swift

let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = .EEA
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
    with: parameters,
    completionHandler: { error in
      ...
    })

Objective-C

UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
debugSettings.geography = UMPDebugGeographyEEA;
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable error){
                           ...
}];

UMP SDK로 앱을 테스트할 때 사용자의 첫 설치 환경을 시뮬레이션할 수 있습니다. SDK에서는 이를 위한 reset 메서드를 제공합니다.

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

GitHub의 예

UMP SDK 통합 예: Swift | Objective-C