Search Unity

Need Help with prime31 iAD

Discussion in 'Scripting' started by Niki.j, Sep 5, 2013.

  1. Niki.j

    Niki.j

    Joined:
    Oct 17, 2012
    Posts:
    157
    Hello All,

    I am using prime31 iAd_2013 plugin for the first time.
    There I want a response from the server when the ad gets displayed on the screen, so that i can decrease the my game play area accordingly.
    Also I want to show and hide the iAds, but i can not find any way to do this.

    Do any one have any solution for my problem...then please guide me.

    Thank you in advance for the help and sorry for rent.
    Niki.j
     
  2. Niki.j

    Niki.j

    Joined:
    Oct 17, 2012
    Posts:
    157
    Hello guys...

    Any update...????
    You can find the code here that i am trying:


    the code where i am calling all the required functions from the prime31 iAd plugin are:
    Code (csharp):
    1.  
    2.  
    3. void Update()
    4.     {
    5.         if(Time.frameCount % 10 == 0)
    6.         {
    7.             AdBinding.fireHideShowEvents(true);
    8.             AdBinding.createAdBanner();
    9.         }
    10.     }
    11.  
    12.  

    AdManager.cs

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Collections;
    5. using Prime31;
    6.  
    7.  
    8. #if UNITY_IPHONE
    9. public class AdManager : AbstractManager
    10. {
    11.     // Fired when the adView is either shown or hidden
    12.     public static event Action<bool> adViewDidChange;
    13.    
    14.     // Fired when an interstial ad fails to load or show
    15.     public static event Action<string> interstitalAdFailed;
    16.    
    17.     // Fired when an interstitial ad is loaded and ready to show
    18.     public static event Action interstitialAdLoaded;
    19.    
    20.     public static bool adViewIsShowing = false;
    21.    
    22.     private string mystr;
    23.     public static bool isAdVisible;
    24.    
    25.     static AdManager()
    26.     {
    27.         AbstractManager.initialize( typeof( AdManager ) );
    28.     }
    29.  
    30.     public void adViewDidShow(string returnValue)
    31.     {
    32.         adViewIsShowing = ( returnValue == "1" );
    33.         adViewDidChange.fire( adViewIsShowing );
    34.         Debug.Log("nitin iAd called ->"+ returnValue);
    35.         mystr = returnValue;
    36.         if(mystr == "1")
    37.             isAdVisible = true;
    38.         else
    39.             isAdVisible = false;
    40.     }
    41.    
    42.     public void interstitialFailed( string error )
    43.     {
    44.         interstitalAdFailed.fire( error );
    45.     }
    46.    
    47.    
    48.     public void interstitialLoaded( string empty )
    49.     {
    50.         interstitialAdLoaded.fire();
    51.     }
    52. }
    53. #endif
    54.  

    AdBinding.cs

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Runtime.InteropServices;
    4.  
    5.  
    6. public static class AdBinding
    7. {
    8.     [DllImport("__Internal")]
    9.     private static extern void _iAdCreateAdBanner( bool bannerOnBottom );
    10.  
    11.     // Starts up iAd requests and ads the ad view
    12.     public static void createAdBanner( bool bannerOnBottom )
    13.     {
    14.         // Call plugin only when running on real device
    15.         if( Application.platform == RuntimePlatform.IPhonePlayer )
    16.             _iAdCreateAdBanner( bannerOnBottom );
    17.     }
    18.    
    19.     [DllImport("__Internal")]
    20.     private static extern void _iAdDestroyAdBanner();
    21.  
    22.     // Destroys the ad banner and removes it from view
    23.     public static void destroyAdBanner()
    24.     {
    25.         // Call plugin only when running on real device
    26.         if( Application.platform == RuntimePlatform.IPhonePlayer )
    27.             _iAdDestroyAdBanner();
    28.     }  
    29.  
    30.  
    31.     [DllImport("__Internal")]
    32.     private static extern void _iAdFireHideShowEvents( bool shouldFire );
    33.  
    34.     // Switches the orientation of the ad view
    35.     public static void fireHideShowEvents( bool shouldFire )
    36.     {
    37.         // Call plugin only when running on real device
    38.         Debug.Log("in AdBinding -> fireHideShowEvents -> shouldFire = " + shouldFire);
    39.        
    40.         if( Application.platform == RuntimePlatform.IPhonePlayer )
    41.             _iAdFireHideShowEvents( shouldFire );
    42.     }
    43.  
    44.  
    45.     [DllImport("__Internal")]
    46.     private static extern bool _iAdInitializeInterstitial();
    47.  
    48.     // Starts loading a new interstitial ad.  Returns false when interstitials are not supported.
    49.     public static bool initializeInterstitial()
    50.     {
    51.         if( Application.platform == RuntimePlatform.IPhonePlayer )
    52.             return _iAdInitializeInterstitial();
    53.  
    54.         return false;
    55.     }
    56.  
    57.  
    58.     [DllImport("__Internal")]
    59.     private static extern bool _iAdInterstitialIsLoaded();
    60.  
    61.     // Checks to see if an interstitial ad is loaded.
    62.     public static bool isInterstitalLoaded()
    63.     {
    64.         if( Application.platform == RuntimePlatform.IPhonePlayer )
    65.             return _iAdInterstitialIsLoaded();
    66.  
    67.         return false;
    68.     }
    69.  
    70.  
    71.     [DllImport("__Internal")]
    72.     private static extern bool _iAdShowInterstitial();
    73.  
    74.     // Shows an interstitial ad.  Will return false if it isn't loaded.
    75.     public static bool showInterstitial()
    76.     {
    77.         if( Application.platform == RuntimePlatform.IPhonePlayer )
    78.             return _iAdShowInterstitial();
    79.  
    80.         return false;
    81.     }
    82.    
    83. }
    84.  
    85.  
    I am able to show the iAds but i need to decrease the size of screen when iAd will come on the screen, to do that i am looking for any response from the server end, but not able to get that, please help me if any one having any idea bout my problem.....

    Thanks in Advance!
    Niki.j
     
  3. Niki.j

    Niki.j

    Joined:
    Oct 17, 2012
    Posts:
    157
    Hello,

    Finally i have find the way.
    here is the code for iAds.....
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class AdAdapter : MonoBehaviour
    5. {
    6.     public bool bannerOnBottom = true;
    7.     public bool isAdShowing;
    8. #if UNITY_IPHONE
    9.    
    10.     public void Start()
    11.     {
    12.         // start up iAd and destroy ourself
    13.         AdBinding.createAdBanner( bannerOnBottom );
    14.         AdBinding.fireHideShowEvents(true);
    15.         AdManager.adViewDidChange += HandleAdManageradViewDidChange;
    16.         //Destroy( gameObject );
    17.     }
    18.  
    19.     void HandleAdManageradViewDidChange (bool obj)
    20.     {
    21.         isAdShowing = obj;
    22.     }
    23. #endif
    24. }
    25.  
    any one just need to create an empty game object and assign this script on the same will start working for your iAds also you can get the response in isAdShowing as bool.