Başlayın

Google AB Kullanıcı İzni kapsamında Politika'yı ihlal etmiyorsa Avrupa Ekonomik Alanı'ndaki (AEA) kullanıcılarınıza belirli açıklamalar Birleşik Krallık'ta oturum açıp çerez veya başka yerel depolama alanlarını kullanmak için ve reklam yayınlamak için kişisel verileri (Reklam Kimliği gibi) kullanmak. Bu politika AB eGizlilik Yönergesi ve (Genel Veri Koruma Yönetmeliği)

Google, yayıncıları bu politika kapsamındaki gereksinimleri yerine getirmeleri konusunda desteklemek amacıyla Kullanıcı Mesajlaşma Platformu (UMP) SDK'sı. UMP SDK'sı, en son IAB standartlarına uyun. Bu yapılandırmaların hepsi artık çok kolay AdMob gizlilik ve bahsedeceğim.

Ön koşullar

Mesaj türü oluşturma

Kullanıcı mesajlarını . kullanılabilir kullanıcı mesajı türleri Gizlilik ve mesajlaşma AdMob hesap. UMP SDK'sı bir AdMob Uygulama Kimliği'nden oluşturulan kullanıcı mesajı birçok yolu vardır. Uygulamanız için herhangi bir mesaj yapılandırılmamışsa SDK, hata döndürür.

Daha fazla bilgi için bkz. . Gizlilik ve mesajlaşma hakkında

SDK'yı içe aktarma

CocoaPods (tercih edilen)

SDK'yı bir iOS projesine aktarmanın en kolay yolu CocoaPods'da bulabilirsiniz. Projenizin Podfile'a gidin ve bu satırı uygulamanızın hedefine ekleyin:

pod 'GoogleUserMessagingPlatform'

Ardından aşağıdaki komutu çalıştırın:

pod install --repo-update

CocoaPods'u kullanmaya yeni başladıysanız Ayrıntılı bilgi için CocoaPods'a göz atın: ve Podfiles'i kullanın.

Swift Paket Yöneticisi

UMP SDK'sı, Swift Package Manager'ı da destekler. Aşağıdaki adımları uygulayarak içe aktaracağım.

  1. Xcode'da şuraya giderek UMP SDK Swift Paketini yükleyin: Dosya > Paket Ekle...

  2. Görüntülenen istemde UMP SDK Swift Package GitHub'ı arayın depo:

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. Kullanmak istediğiniz UMP SDK Swift Paketi sürümünü seçin. Yeni Bir Sonraki Ana Sürüm'ü kullanmanızı öneririz.

Daha sonra Xcode, paket bağımlılıklarınızı çözer ve bunları arka plan. Paket bağımlılıkları ekleme hakkında daha fazla bilgi için Apple'ın makalesine bakın.

Manuel indirme

SDK'yı içe aktarmanın diğer yolu ise bu işlemi manuel olarak yapmaktır.

SDK'yı indir

Ardından çerçeveyi Xcode projenize sürükleyin ve Kopyala kontrol edin.

Ardından, aşağıdaki komutu kullanarak çerçeveyi ihtiyacınız olan herhangi bir dosyaya ekleyebilirsiniz:

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

Uygulama kimliğini ekleyin

Uygulama kimliğinizi şurada bulabilirsiniz: . AdMob kullanıcı arayüzü. . Kimliği Info.plist aşağıdaki kod snippet'i ile:

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

Her uygulamada kullanıcının rıza bilgilerinin güncellenmesini istemelisiniz. requestConsentInfoUpdateWithParameters:completionHandler:kullanarak başlat. Bu, kullanıcıların Kullanıcı daha önce izin vermediyse izin vermesi gerekip gerekmediğini veya kullanıcı rızasının geçerlilik süresi sona erdiyse.

Şuradaki UIViewController durumunun nasıl kontrol edileceğine dair bir örnek: viewDidLoad() yöntemini çağırın.

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

Gerekirse bir izin formu yükleyin ve gösterin

En güncel izin durumunu aldıktan sonra loadAndPresentIfRequiredFromViewController:completionHandler: şurada: UMPConsentForm sınıflayın. Öğe SDK, izin durumu gerekli olduğunda bir form yükleyip anında kaynak: view controller. completion handler aranır form kapatıldıktan sonra. İzin gerekmiyorsa completion handler durumunda çalışılır.

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

Kullanıcı seçim yaptıktan veya kapatıldıktan sonra herhangi bir işlem yapmanız gerekirse mantığını completion handlerbölümüne yerleştirin. seçin.

Reklam isteğinde bulun

Uygulamanızda reklam isteğinde bulunmadan önce izin alıp almadığınızı kontrol edin UMPConsentInformation.sharedInstance.canRequestAdskullanan kullanıcıdan. İki tür izin alınırken kontrol edilecek yerler:

  1. Mevcut oturumda izin alındıktan sonra.
  2. requestConsentInfoUpdateWithParameters:completionHandler:adlı kişiyi aramanızın hemen ardından. Önceki oturumda izin alınmış olabilir. Gecikme olarak en iyi uygulama olarak, geri arama işleminin tamamlanmasını beklememenizi öneririz. Uygulamanız kullanıma sunulduktan hemen sonra reklam yüklemeye başlamanızı öneririz.

İzin alma sürecinde bir hata oluşursa reklam isteğinde bulunmayı deneyin. UMP SDK'sı, Search Ads 360'ta önceki kabul edilir.

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

Gizlilik seçenekleri

Bazı izin formlarında, kullanıcının istediği zaman iznini değiştirmesi gerekir. Bağlı olun gizlilik seçenekleri düğmesi uygulamak için aşağıdaki adımlara uygulayın.

Bunu yapabilmek için:

  1. Uygulamanızın ayarlar sayfasındaki bir düğme gibi kullanıcı arayüzü öğesi uygulayın. gizlilik seçenekleri formunu tetikleyebilecek şekilde açıklayabilirsiniz.
  2. Tamamlandığında loadAndPresentIfRequiredFromViewController:completionHandler: kontrol edin karar vermek için kullanılanprivacyOptionsRequirementStatus gizlilik seçenekleri formunu sunabilen kullanıcı arayüzü öğesi.
  3. Bir kullanıcı, UI öğenizle etkileşime geçtiğinde presentPrivacyOptionsFormFromViewController:completionHandler: Böylece formu göstererek gizlilik seçeneklerini diledikleri zaman güncelleyebilirler.

Aşağıdaki örnekte, gizlilik seçenekleri formunun 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.
                                  }
                                }];
}

Test

Geliştirme sürecinde uygulamanızdaki entegrasyonu test etmek isterseniz bu adımları izleyerek test cihazınızı programlı olarak kaydedin. Etiketinizi kaldırdığınızda uygulamanızı yayınlamadan önce bu test cihazı kimliklerini belirleyen koddur.

.
  1. requestConsentInfoUpdateWithParameters:completionHandler:numaralı telefonu arayın.
  2. Aşağıdaki örneğe benzer bir mesaj için günlük çıkışını kontrol edin: cihaz kimliğinizi ve test cihazı olarak nasıl ekleyeceğinizi gösterir:

    <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
    
  3. Test cihazınızın kimliğini panoya kopyalayın.

  4. Kodunuzu şu şekilde değiştirin: için UMPDebugSettings().testDeviceIdentifiers ve pas test cihazı kimliklerinizin listesi.

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

Bir coğrafi bölgeyi zorunlu kılın

UMP SDK'sı, uygulamanızın davranışını cihaz sanki AEA veya Birleşik Krallık'ta the debugGeography property of type UMPDebugGeography on UMPDebugSettingskullanarak bulabilirsiniz. Lütfen Hata ayıklama ayarları yalnızca test cihazlarında çalışır.

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

Uygulamanızı UMP SDK'sı ile test ederken kullanıcının ilk yükleme deneyimini simüle edebilmek için SDK durumunu kontrol edin. SDK, bunu yapmak için reset yöntemini sağlar.

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

GitHub'daki örnekler

. UMP SDK'sı entegrasyon örnekleri: Swift | Objective-C