Search Unity

It does not work on the phone

Discussion in 'Unity Ads & User Acquisition' started by AJDB, Oct 9, 2015.

  1. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    16
    Hello I am new here, and I have a problem.

    I am integrating UnityADS, and I pc works fine even connect the phone via the Remote Unit, but when I generate the apk and install on your phone, not working.
    Want ads shown even more pressing the button to exit the game, and after the end of the game show the video display.
    As I say the PC works well as it is easy to implement, but with the apk, no.
    Can someone help me out?.
    Thank you.
    Sorry if my English is not good.
     
  2. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    Can you please provide a simple example, showing how you are initializing and showing ads?
     
  3. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    16
    Hello Rasmus-unity, as I said on the phone, with the apk, not shown, and if PC.
    I followed the tutorial they have on their website here: https://unity3d.com/es/learn/tutorials/modules/beginner/live-training-archive/integrating-ads
    In the PC shown in the video as well, it not if you ask me is a snapshot, as seen on the PC. If so, it's like in the tutorial.
    I have a button, which causes change of scene, the game, the score screen when the player wants to stop playing, and that's when I want the announcement mueste before changing scene and show the scene scoring .
    It is how I want it to work, and work (only pc).
    I forgot to say that installed on the phone, what it does is it returns to the game screen, without going through the score.
    Jo part of the code that have changed, the rest is the same as the tutorial (changing the ID clear jjj).

    Code (CSharp):
    1.     IEnumerator WaitForAd()
    2.     {
    3.         float currentTimeScale = Time.timeScale;
    4.         Time.timeScale = 0f;
    5.         yield return null;
    6.      
    7.         while (Advertisement.isShowing)
    8.             yield return null;
    9.         Application.LoadLevel("Final");
    10.         Time.timeScale = currentTimeScale;
    11.     }
     
    Last edited by a moderator: Oct 14, 2015
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    You dont call Advertisement.Show() in that code. How do you expect it to work if you're not showing any ads.

    Also, your method of waiting for ad to finish via co-routine is aweful. But if youre new to coding, no biggie. The proper way is to hook into ad events.
     
  5. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    16
    Hello, JamesLeeNZ, if I am new to this. But I tell you that since only part of the code, the rest is the same as the tutorial link I put previously, as I should work the same.
    Tell you also that ads are shown, but only on the PC, and Unity Remote. The problem comes when I think the apk file and install it on the phone.
    If I do not have either the code, which would be the right way to do ?.
    And I tell you that I have followed the tutorial, and if you want I leave the complete code.
     
  6. rasmus-unity

    rasmus-unity

    Moderator

    Joined:
    Aug 15, 2014
    Posts:
    1,312
    I suggest you make a basic example, e.g. using the one from https://unityads.unity3d.com/help/D...shers/Integration-Guide-for-Unity-Asset-Store, which hopefully would show that ads actually are displaying correctly on your phone.

    If that still gives problems, take a look at the Android logs (e.g. using "adb logcat" from command line) to see if you get any information from there (network problems etc). If it works, you need to figure out why the code in your game doesn't show ads. But given your code sample above using coroutines, I think you might be able to simplify your code for showing ads.

    -Rasmus
     
  7. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    16
    I have reviewed the documentation you mention me, and see that there are errors to implement only the code. I leave it in the image.
    I tried it with a new project, which explains unity-nikkolai, here: http://forum.unity3d.com/threads/issues-in-migrating-to-5-2.353849/#post-2290349
    I have also put the sample code that comes from the tab Unity - Services, and anyway, I always get the same mistakes.
    I thought it was easy, but I think in the end I have to leave, I've tried everything, and nothing.
     
    elburuzgurbuz likes this.
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Integrating the ads is so easy its not funny.

    Go into Unity Ads Services, setup whats required there. You might need to log into the UnityAds Website/dashboard and setup your game as supporting ads there. I did it a few weeks ago, but I cant remember if the support section built into Unity took care of that part.

    in your code put this somewhere.

    if(Advertisment.IsReady())
    Advertisement.Show();


    Thats it. There more if you want the callback, but for starters, it doesnt get much harder than that. If you turn on Test Mode in Ad Services you will see ads on pc.
     
  9. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    16
    If you are that easy, so I got a little tired, and it seems I'm stupid.
    The issue is also that has changed in the version of Unity, which is what I have.
    I put the code, Ctrl + C and Ctrl + V, the example is Unity, and nothing gives me a lot of mistakes.
    I'll see if I can import the project to 4.6 I already miss tests and doing well.
     
  10. MaestroMMT

    MaestroMMT

    Joined:
    May 31, 2015
    Posts:
    26
    Hello,

    Unity Pro 5.2.1p4.

    Same issue here :/ Works fine on PC but not on mobile :

    Code :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using System;
    4. using System.Collections;
    5.  
    6. public class MyMusicReplayAdds : MonoBehaviour {
    7.  
    8.         public void Start()
    9.         {
    10.             Debug.Log ("*********Display Ads 1********");
    11.  
    12.             if (Advertisement.isSupported) {
    13.                 Advertisement.allowPrecache = true;
    14.                 Advertisement.Initialize ("xxxxxxx", true);
    15.             } else {
    16.                 Debug.Log("Platform not supported");
    17.             }
    18.          
    19.         }
    20.  
    21.         public void ShowAd ()
    22.         {
    23.                 StartCoroutine (ShowAdWhenReady ());
    24.         }
    25.      
    26.         public IEnumerator ShowAdWhenReady()
    27.         {
    28.         Debug.Log ("*******Display Ads 2*******");
    29.             while (!Advertisement.isReady ())
    30.                 yield return null;
    31.          
    32.         Debug.Log ("*******Display Ads 3*******");
    33.             Advertisement.Show ();
    34.         }
    35.  
    36. }
    37.  
    Log "Display Ads 3" is never show.

    Adb logcat log attached below :

    any help will be much apreciated.
     

    Attached Files:

    Last edited: Oct 27, 2015
  11. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    16
    Hola, MaestroMMT, ya he resuelto.
    Hay cambios en el panel de control de la ADS, yo y mi sólo funciona con el ID de la nueva pieza.
    Tuve que crear un nuevo proyecto y poner los nuevos valores en el código.
    El tutorial que he dicho al principio, y he tomado sólo lo que es "verdad", la línea 14
    Advertisement.Initialize ("xxxxxxx", true);
    usted ha puesto su.
     
  12. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    @MaestroMMT I reworked your code a bit. Try this script out instead:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class MyMusicReplayAds : MonoBehaviour
    6. {
    7.     [SerializeField] private string gameId;
    8.     [SerializeField] private string zoneId;
    9.     [SerializeField] private float timeoutDuration = 60f;
    10.     [SerializeField] private bool enableTestMode;
    11.  
    12.     private bool isAttemptingToShowAd;
    13.  
    14.     void Start ()
    15.     {
    16.         Debug.Log ("Initializing Unity Ads for game ID " + gameId +
    17.                    " with test mode " + (enableTestMode ? "enabled." : "disabled.") );
    18.        
    19.         if (Advertisement.isSupported)
    20.         {
    21.             Advertisement.Initialize (gameId, enableTestMode);
    22.         }
    23.         else Debug.Log("Platform not supported.");
    24.     }
    25.  
    26.     void OnDestroy ()
    27.     {
    28.         StopAllCoroutines ();
    29.     }
    30.  
    31.     public void ShowAd ()
    32.     {
    33.         if (!Advertisement.isInitialized)
    34.         {
    35.             Debug.LogWarning ("Unable to show ad. Unity Ads is not initialized.");
    36.             return;
    37.         }
    38.  
    39.         if (!isAttemptingToShowAd)
    40.         {
    41.             isAttemptingToShowAd = true;
    42.             StartCoroutine ( ShowAdWhenReady() );
    43.         }
    44.     }
    45.  
    46.     private IEnumerator ShowAdWhenReady()
    47.     {
    48.         float startTime = Time.time;
    49.  
    50.         Debug.Log ("Attempting to show an ad when ready...");
    51.  
    52.         if (string.IsNullOrEmpty (zoneId)) zoneId = null;
    53.  
    54.         while (!Advertisement.IsReady(zoneId))
    55.         {
    56.             if (Time.time < startTime + timeoutDuration)
    57.             {
    58.                 Debug.Log ("Ad is not ready. Trying again in 1 second...");
    59.                 yield return new WaitForSeconds (1f);
    60.             }
    61.             else
    62.             {
    63.                 Debug.LogWarning ("Ad was not ready in a timely manner. " +
    64.                                   "Canceling attempt to show.");
    65.  
    66.                 HandleShowResult(ShowResult.Failed);
    67.                 yield break;
    68.             }
    69.         }
    70.        
    71.         Debug.Log ("Ad is ready. Showing ad now.");
    72.  
    73.         Advertisement.Show(zoneId, new ShowOptions { resultCallback = HandleShowResult });
    74.     }
    75.  
    76.     private void HandleShowResult (ShowResult result)
    77.     {
    78.         isAttemptingToShowAd = false;
    79.     }
    80. }
    81.  
    Added some checks to avoid any potential issues:
    • using the latest Unity Ads API (see changes)
    • made debug messages more descriptive throughout
    • made serialized private variables so the script doesn't have to be edited
    • checks to see if Unity Ads is initialized before attempting to show
    • checks to see if the script is already attempting to show
    • uses a default timeout of 60 seconds to escape the while loop if the ad isn't able to show in a timely manner
    • defined the OnDestroy method to stop the coroutine if the script instance is destroyed
    If you still aren't able to see ads, run the following commands in terminal before launching your app:

    Code (csharp):
    1. adb logcat -c; adb logcat -s Unity UnityAds
     
    Last edited: Oct 30, 2015
    MaestroMMT likes this.
  13. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
  14. MaestroMMT

    MaestroMMT

    Joined:
    May 31, 2015
    Posts:
    26
    Hello nikkolai and thank you for your time and your nice code, I will use it :D

    Finaly, I found my mystake after a day searching. Both Android and IOS platforms were selected in unity ads service, and you should select only one to see it works.

    Futhermore, I imported ads package from the asset store whereas unity ads was already included in 5.2 (I had a .jar conflict with the existing solution)

    Works fine on android now.
     
  15. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    @MaestroMMT You should be able to have both platforms checked in the Settings section of Ads in the Services window without any issues. It just indicates which platforms should include the built in API.

    If you are using the built in Unity Ads API, you should remove the Unity Ads asset package contents from your project.