Search Unity

Unity Ads Not Working - iOS

Discussion in 'Unity Ads & User Acquisition' started by saultoons, Aug 21, 2019.

  1. saultoons

    saultoons

    Joined:
    Aug 20, 2019
    Posts:
    1
    Hello,

    We recently set up Unity Ads in our game, and in Unity the ad placement, playback, and everything ad related works as intended.

    We then build the project to import to Xcode and then publish to app store connect for testing.
    We get 0 errors when archiving the app, and all goes well in getting the app to app store connect for testflight.

    But upon testing the app, the unity ads popup occurs, you go through the selection and then it plays an ad (We have not coded this in anywhere, and it doesnt do this in Unity). Upon finishing the ad, another ad pops up, and this cycle is repeated:
    upload_2019-8-21_16-1-27.png upload_2019-8-21_16-1-5.png

    Here is the code for our ad manager:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class AdController : MonoBehaviour, IUnityAdsListener
    8. {
    9.     public static AdController instance;
    10.     private SceneManagement sceneMan;
    11.  
    12.     private string store_id = "apple_id";//apple
    13.  
    14.     private string video_ad = "video";
    15.     private string rewarded_video_ad = "rewardedVideo";
    16.  
    17.     private void Awake()
    18.     {
    19.         if(instance != null)
    20.         {
    21.             Destroy(gameObject);
    22.         }
    23.         else
    24.         {
    25.             instance = this;
    26.             DontDestroyOnLoad(gameObject);
    27.         }
    28.     }
    29.  
    30.     void Start()
    31.     {
    32.         Advertisement.AddListener(this);
    33.         Advertisement.Initialize(store_id, true); // this will be false when we release
    34.  
    35.         if(SceneManager.GetActiveScene().buildIndex == 1)
    36.         {
    37.             sceneMan = GameObject.Find("SceneManager").GetComponent<SceneManagement>();        
    38.         }
    39.      
    40.     }
    41.  
    42.     public void showvideoad() //Skippable
    43.     {
    44.         if (Advertisement.IsReady(video_ad))
    45.         {
    46.             Advertisement.Show(video_ad);
    47.         }
    48.  
    49.     }
    50.  
    51.     public void ShowRewardedVideo()
    52.     {
    53.         AudioManager.instance.Stop("MenuMusic");
    54.         Advertisement.Show(rewarded_video_ad);
    55.     }
    56.  
    57.     public void OnUnityAdsDidFinish(string rewarded_video_ad, ShowResult showresult) //Unskippable
    58.     {
    59.         if (showresult == ShowResult.Finished)
    60.         {
    61.             if (SceneManager.GetActiveScene().buildIndex == 0)
    62.             {
    63.                 GameManager.Instance.gold += 50;
    64.                 PlayerPrefs.SetInt("gold", GameManager.Instance.gold);
    65.             }
    66.  
    67.             if (SceneManager.GetActiveScene().buildIndex == 1)
    68.             {
    69.                 sceneMan = GameObject.Find("SceneManager").GetComponent<SceneManagement>();
    70.  
    71.                 if (!sceneMan.playerController.GetComponent<PlayerController>().gameEnded)
    72.                 {
    73.                     print("This shouldnt happen Either");
    74.                     sceneMan.deathPanelButtons.SetActive(false);
    75.                     sceneMan.player.SetActive(true);
    76.                     sceneMan.playerController.GetComponent<PlayerController>().health = 1;
    77.                     GameManager.Instance.playerAlive = true;
    78.                     StartCoroutine(sceneMan.PayGoldToCont());
    79.                 }
    80.  
    81.                 if (sceneMan.playerController.GetComponent<PlayerController>().gameEnded)
    82.                 {
    83.                     print("This shouldnt happen");
    84.                     sceneMan.DoubleGoldReward();
    85.                 }
    86.  
    87.             }
    88.         }
    89.  
    90.         else if (showresult == ShowResult.Failed)
    91.         {
    92.             //Debug.Log("Failed to show advert");
    93.         }
    94.     }
    95.  
    96.     public void OnUnityAdsDidError(string message)
    97.     {
    98.  
    99.     }
    100.  
    101.     public void OnUnityAdsReady(string rewarded_video_ad)
    102.     {
    103.         Advertisement.Show(rewarded_video_ad);
    104.     }
    105.  
    106.     public void OnUnityAdsDidStart(string placementId)
    107.     {
    108.         print("Helo");
    109.     }
    110.  
    111. }
    112.  

    Any ideas would be greatly appreciated because we are truly lost, and at the point of thinking about removing unity ads altogether and trying a different ads service.

    Thanks,

    Liam
     
    Last edited: Aug 21, 2019
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    How are you debugging? Using Debug.Log is an easy way, the output will show in the logs. My suspicion is OnUnityAdsReady, you call Advertisement.Show which might trigger OnUnityAdsReady again, etc. You might want to place a Debug.Log statement there to confirm, or breakpoint/step debug from XCode.