Skip to content

Commit

Permalink
Update HelloWorld sample with RequestConfiguration.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 308714127
  • Loading branch information
Samuel Stow authored and maddevrelgithubbot committed Apr 27, 2020
1 parent 5362545 commit 4dc1bd1
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions samples/HelloWorld/Assets/Scripts/GoogleAdMobController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using UnityEngine.Events;
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;
using UnityEngine.UI;
using System;
using System.Collections.Generic;

public class GoogleAdMobController : MonoBehaviour
{
Expand All @@ -28,15 +30,37 @@ public void Start()
{
MobileAds.SetiOSAppPauseOnBackground(true);

List<String> deviceIds = new List<String>() { AdRequest.TestDeviceSimulator };

// Add some test device IDs (replace with your own device IDs).
#if UNITY_IPHONE
deviceIds.Add("96e23e80653bb28980d3f40beb58915c");
#elif UNITY_ANDROID
deviceIds.Add("75EF8D155528C04DACBBA6F36F433035");
#endif

// Configure TagForChildDirectedTreatment and test device IDs.
RequestConfiguration requestConfiguration =
new RequestConfiguration.Builder()
.SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.Unspecified)
.SetTestDeviceIds(deviceIds).build();

MobileAds.SetRequestConfiguration(requestConfiguration);

// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(HandleInitCompleteAction);

RequestAndLoadRewardedAd();
}

private void HandleInitCompleteAction(InitializationStatus initStatus)
private void HandleInitCompleteAction(InitializationStatus initstatus)
{
statusText.text = "Initialization complete";
// Callbacks from GoogleMobileAds are not guaranteed to be called on
// main thread.
// In this example we use MobileAdsEventExecutor to schedule these calls on
// the next Update() loop.
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "Initialization complete";
RequestBannerAd();
});
}

private void Update()
Expand Down

0 comments on commit 4dc1bd1

Please sign in to comment.