Wypróbuj

Obowiązujące w Google zgoda użytkownika z UE , musisz udzielać odpowiednich informacji użytkownikom z Europejskiego Obszaru Gospodarczego (EOG) oraz z Wielką Brytanią i uzyskać ich zgodę na używanie plików cookie lub innych sposobów lokalnego przechowywania informacji, jeśli wymaga tego prawo, oraz wykorzystywać dane osobowe (np. AdID) do wyświetlania reklam. Polityka ta odzwierciedla wymagania UE zawarte w dyrektywie o prywatności i łączności elektronicznej Ogólnego rozporządzenia o ochronie danych (RODO).

Aby pomóc wydawcom w wypełnieniu obowiązków, jakie nakłada na nich ta polityka, Google oferuje pakiet SDK User Messaging Platform (UMP). Pakiet UMP SDK obsługuje teraz zgodne z najnowszymi standardami IAB. Wszystkie te konfiguracje można teraz w wygodny sposób obsługiwane w Ad Manager ustawieniach prywatności i wysyłanie wiadomości.

Wymagania wstępne

Tworzenie typu wiadomości

Utwórz wiadomości dla użytkowników za pomocą jednej z tych metod: dostępne typy wiadomości dla użytkowników w sekcji Prywatność na karcie „Wiadomości” Ad Manager koncie. Pakiet UMP SDK próbuje wyświetlić wiadomość dla użytkownika utworzona Ad Manager na podstawie identyfikatora aplikacji ustawione w projekcie. Jeśli dla aplikacji nie jest skonfigurowany żaden komunikat, pakiet SDK zwraca błąd.

Więcej informacji: Prywatność i wyświetlanie wiadomości

Importowanie pakietu SDK

CocoaPods (preferowane)

Najprostszym sposobem zaimportowania pakietu SDK do projektu iOS jest użycie CocoaPods. Otwórz w swoim projekcie Podfile i dodaj ten wiersz do miejsca docelowego aplikacji:

pod 'GoogleUserMessagingPlatform'

Następnie uruchom to polecenie:

pod install --repo-update

Jeśli dopiero zaczynasz korzystać z CocoaPods, przeczytaj artykuł Korzystanie z tej usługi. CocoaPods. tworzenia i używania plików Podfiles.

Menedżer pakietów Swift

Pakiet UMP SDK obsługuje też menedżera pakietów Swift. Wykonaj te czynności, aby importowanie pakietu Swift.

  1. Zainstaluj w Xcode pakiet UMP SDK Swift. W tym celu przejdź na stronę Plik > Dodaj pakiety...

  2. W wyświetlonym oknie wyszukaj pakiet UMP SDK Swift na GitHubie. repozytorium:

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. Wybierz wersję pakietu UMP SDK Swift, którego chcesz użyć. Nowe zalecamy korzystanie z wersji do następnej głównej wersji.

Xcode rozwiązuje zależności pakietów i pobiera je do w tle. Więcej informacji o dodawaniu zależności pakietów znajdziesz w dokumencie Apple .

Pobieranie ręczne

Innym sposobem importowania pakietu SDK jest zrobienie tego ręcznie.

Pobierz pakiet SDK

Następnie przeciągnij platformę do projektu Xcode, zaznaczając opcję Kopiuj w razie potrzeby.

Następnie możesz dodać tę platformę do dowolnego pliku, używając:

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

Dodaj identyfikator aplikacji

Identyfikator aplikacji znajdziesz w Interfejs Ad Managera. Dodaj dokument tożsamości do Info.plist z następującym fragmentem kodu:

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

Informacje o zgodzie użytkownika należy wysyłać w każdej aplikacji za pomocą funkcji requestConsentInfoUpdateWithParameters:completionHandler:. Określa to czy użytkownik musi wyrazić zgodę, jeśli jeszcze tego nie zrobił; czy ich zgoda wygasła.

Oto przykład, jak sprawdzić stan elementu UIViewController w Metoda 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 consent 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 consent form.
          }];
}

W razie potrzeby wczytaj i wyświetl formularz zgody

Po uzyskaniu najbardziej aktualnego stanu zgody zadzwoń pod numer loadAndPresentIfRequiredFromViewController:completionHandler: w UMPConsentForm klasy, aby wczytać formularz zgody. Jeśli jest wymagany stan zgody użytkownika, pakiet SDK wczytuje formularz i od razu go wyświetla z podanego view controller. completion handler jest wywoływany po zamknięciu formularza. Jeśli zgoda nie jest wymagana, completion handler jest wywoływany natychmiast.

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.
                }];
          }];
}

Jeśli musisz wykonać jakieś działania po dokonaniu wyboru lub odrzuceniu go przez użytkownika umieść tę logikę w elemencie completion handler dla swojego formularza.

Wyślij żądanie

Zanim wyślesz prośbę o reklamy w aplikacji, sprawdź, czy masz jej zgodę od użytkownika za pomocą funkcji UMPConsentInformation.sharedInstance.canRequestAds. Dostępne są 2 które sprawdzić podczas uzyskiwania zgody użytkowników:

  1. Po uzyskaniu zgody użytkownika w bieżącej sesji.
  2. Zaraz po nawiązaniu połączenia z firmą requestConsentInfoUpdateWithParameters:completionHandler:. Możliwe, że w poprzedniej sesji użytkownik wyraził zgodę. Jako opóźnienie zgodnie ze sprawdzoną metodą, nie czekaj na zakończenie połączenia, ponieważ będzie można ładowanie reklam od razu po uruchomieniu aplikacji.

Jeśli w trakcie procesu uzyskiwania zgody użytkowników wystąpi błąd, żądania reklam. Pakiet UMP SDK używa stanu zgody z poprzedniej wersji .

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...];
  });
}

Opcje prywatności

Niektóre formularze zgody wymagają od użytkownika zmiany zgody w dowolnym momencie. Stosowanie wykonaj poniższe kroki, by w razie potrzeby zaimplementować przycisk opcji prywatności.

W tym celu:

  1. Zaimplementuj element interfejsu, np. przycisk na stronie ustawień aplikacji, które może wyświetlić formularz opcji prywatności.
  2. Po loadAndPresentIfRequiredFromViewController:completionHandler: zakończeniu sprawdź, privacyOptionsRequirementStatus , aby określić, czy element interfejsu, który może wyświetlać formularz opcji prywatności.
  3. Gdy użytkownik wejdzie w interakcję z elementem interfejsu, wywołaj presentPrivacyOptionsFormFromViewController:completionHandler: aby wyświetlić formularz, aktualizować swoje opcje prywatności w dowolnym momencie.

Przykład poniżej pokazuje, jak wyświetlić formularz opcji prywatności UIBarButtonItem.

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.
                                  }
                                }];
}

Testowanie

Jeśli chcesz przetestować integrację w aplikacji w trakcie jej tworzenia, postępuj zgodnie z instrukcjami te kroki, by automatycznie zarejestrować urządzenie testowe. Pamiętaj, aby usunąć który będzie ustawiać te identyfikatory urządzeń testowych przed opublikowaniem aplikacji.

  1. Zadzwoń pod numer requestConsentInfoUpdateWithParameters:completionHandler:.
  2. Sprawdź, czy w danych wyjściowych dziennika znajduje się komunikat podobny do poniższego przykładu, który pokazuje identyfikator Twojego urządzenia i jak dodać je jako urządzenie testowe:

    <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
    
  3. Skopiuj identyfikator urządzenia testowego do schowka.

  4. Zmodyfikuj swój kod, aby połączenia UMPDebugSettings().testDeviceIdentifiers i przekaż listę identyfikatorów urządzeń testowych.

    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){
                              ...
    }];
    

Wymuś użycie lokalizacji geograficznej

Pakiet UMP SDK umożliwia przetestowanie działania aplikacji w taki sposób, jakby urządzenie przebywających w Europejskim Obszarze Gospodarczym lub Wielkiej Brytanii za pomocą usługi the debugGeography property of type UMPDebugGeography on UMPDebugSettings. Pamiętaj, że ustawienia debugowania działają tylko na urządzeniach testowych.

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){
                           ...
}];

Podczas testowania aplikacji za pomocą pakietu SDK UMP pomocne może być zresetowanie pliku pakietu SDK, co pozwala symulować pierwszą instalację u użytkownika. Pakiet SDK udostępnia metodę reset .

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

Przykłady w GitHubie

Przykłady integracji pakietu UMP SDK: Swift | Objective-C