Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Maestro Beginner · Aug 21, 2015 at 12:45 PM · iosdestroyadmobbanner

Admob IOS, destroy the banner. [REAL NEED HELP]

There is a problem that took me 3 days. Be kind and help me please.

Use the official plugin admob for ios - https://github.com/googleads/googleads-mobile-plugins

Let down the proper script is an example of the plugin:

     using System;
     using UnityEngine;
     using GoogleMobileAds;
     using GoogleMobileAds.Api;
     
     public class GoogleMobileAdsDemoHandler : IInAppPurchaseHandler
     {
         private readonly string[] validSkus = { "android.test.purchased" };
     
         //Will only be sent on a success.
         public void OnInAppPurchaseFinished(IInAppPurchaseResult result)
         {
             result.FinishPurchase();
             GoogleMobileAdsDemoScript.OutputMessage = "Purchase Succeeded! Credit user here.";
         }
     
         //Check SKU against valid SKUs.
         public bool IsValidPurchase(string sku)
         {
             foreach(string validSku in validSkus) {
                 if (sku == validSku) {
                     return true;
                 }
             }
             return false;
         }
     
         //Return the app's public key.
         public string AndroidPublicKey
         {
             //In a real app, return public key instead of null.
             get { return null; }
         }
     }
     
     // Example script showing how to invoke the Google Mobile Ads Unity plugin.
     public class GoogleMobileAdsDemoScript : MonoBehaviour
     {
     
         private BannerView bannerView;
         private InterstitialAd interstitial;
         private static string outputMessage = "";
     
         public static string OutputMessage
         {
             set { outputMessage = value; }
         }
     
         void OnGUI()
         {
             // Puts some basic buttons onto the screen.
             GUI.skin.button.fontSize = (int) (0.05f * Screen.height);
             GUI.skin.label.fontSize = (int) (0.025f * Screen.height);
     
             Rect requestBannerRect = new Rect(0.1f * Screen.width, 0.05f * Screen.height,
                                        0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(requestBannerRect, "Request Banner"))
             {
                 RequestBanner();
             }
     
             Rect showBannerRect = new Rect(0.1f * Screen.width, 0.175f * Screen.height,
                                            0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(showBannerRect, "Show Banner"))
             {
                 bannerView.Show();
             }
     
             Rect hideBannerRect = new Rect(0.1f * Screen.width, 0.3f * Screen.height,
                                            0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(hideBannerRect, "Hide Banner"))
             {
                 bannerView.Hide();
             }
     
             Rect destroyBannerRect = new Rect(0.1f * Screen.width, 0.425f * Screen.height,
                                               0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(destroyBannerRect, "Destroy Banner"))
             {
                 bannerView.Destroy();
             }
     
             Rect requestInterstitialRect = new Rect(0.1f * Screen.width, 0.55f * Screen.height,
                                                     0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(requestInterstitialRect, "Request Interstitial"))
             {
                 RequestInterstitial();
             }
     
             Rect showInterstitialRect = new Rect(0.1f * Screen.width, 0.675f * Screen.height,
                                                  0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(showInterstitialRect, "Show Interstitial"))
             {
                 ShowInterstitial();
             }
     
             Rect destroyInterstitialRect = new Rect(0.1f * Screen.width, 0.8f * Screen.height,
                                                     0.8f * Screen.width, 0.1f * Screen.height);
             if (GUI.Button(destroyInterstitialRect, "Destroy Interstitial"))
             {
                 interstitial.Destroy();
             }
     
             Rect textOutputRect = new Rect(0.1f * Screen.width, 0.925f * Screen.height,
                                        0.8f * Screen.width, 0.05f * Screen.height);
             GUI.Label(textOutputRect, outputMessage);
         }
     
         private void RequestBanner()
         {
             #if UNITY_EDITOR
                 string adUnitId = "unused";
             #elif UNITY_ANDROID
                 string adUnitId = "INSERT_ANDROID_BANNER_AD_UNIT_ID_HERE";
             #elif UNITY_IPHONE
             string adUnitId = "ca-app-pub-2594771142017764/4411294338";
             #else
                 string adUnitId = "unexpected_platform";
             #endif
     
             // Create a 320x50 banner at the top of the screen.
             bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
             // Register for ad events.
             bannerView.AdLoaded += HandleAdLoaded;
             bannerView.AdFailedToLoad += HandleAdFailedToLoad;
             bannerView.AdOpened += HandleAdOpened;
             bannerView.AdClosing += HandleAdClosing;
             bannerView.AdClosed += HandleAdClosed;
             bannerView.AdLeftApplication += HandleAdLeftApplication;
             // Load a banner ad.
             bannerView.LoadAd(createAdRequest());
         }
     
         private void RequestInterstitial()
         {
             #if UNITY_EDITOR
                 string adUnitId = "unused";
             #elif UNITY_ANDROID
                 string adUnitId = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE";
             #elif UNITY_IPHONE
                 string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
             #else
                 string adUnitId = "unexpected_platform";
             #endif
     
             // Create an interstitial.
             interstitial = new InterstitialAd(adUnitId);
             // Register for ad events.
             interstitial.AdLoaded += HandleInterstitialLoaded;
             interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad;
             interstitial.AdOpened += HandleInterstitialOpened;
             interstitial.AdClosing += HandleInterstitialClosing;
             interstitial.AdClosed += HandleInterstitialClosed;
             interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
             GoogleMobileAdsDemoHandler handler = new GoogleMobileAdsDemoHandler();
             interstitial.SetInAppPurchaseHandler(handler);
             // Load an interstitial ad.
             interstitial.LoadAd(createAdRequest());
         }
     
         // Returns an ad request with custom ad targeting.
         private AdRequest createAdRequest()
         {
             return new AdRequest.Builder()
                     .AddTestDevice(AdRequest.TestDeviceSimulator)
                     .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
                     .AddKeyword("game")
                     .SetGender(Gender.Male)
                     .SetBirthday(new DateTime(1985, 1, 1))
                     .TagForChildDirectedTreatment(false)
                     .AddExtra("color_bg", "9B30FF")
                     .Build();
     
         }
     
         private void ShowInterstitial()
         {
             if (interstitial.IsLoaded())
             {
                 interstitial.Show();
             }
             else
             {
                 print("Interstitial is not ready yet.");
             }
         }
     
         #region Banner callback handlers
     
         public void HandleAdLoaded(object sender, EventArgs args)
         {
             print("HandleAdLoaded event received.");
         }
     
         public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
         {
             print("HandleFailedToReceiveAd event received with message: " + args.Message);
         }
     
         public void HandleAdOpened(object sender, EventArgs args)
         {
             print("HandleAdOpened event received");
         }
     
         void HandleAdClosing(object sender, EventArgs args)
         {
             print("HandleAdClosing event received");
         }
     
         public void HandleAdClosed(object sender, EventArgs args)
         {
             print("HandleAdClosed event received");
         }
     
         public void HandleAdLeftApplication(object sender, EventArgs args)
         {
             print("HandleAdLeftApplication event received");
         }
     
         #endregion
     
         #region Interstitial callback handlers
     
         public void HandleInterstitialLoaded(object sender, EventArgs args)
         {
             print("HandleInterstitialLoaded event received.");
         }
     
         public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
         {
             print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
         }
     
         public void HandleInterstitialOpened(object sender, EventArgs args)
         {
             print("HandleInterstitialOpened event received");
         }
     
         void HandleInterstitialClosing(object sender, EventArgs args)
         {
             print("HandleInterstitialClosing event received");
         }
     
         public void HandleInterstitialClosed(object sender, EventArgs args)
         {
             print("HandleInterstitialClosed event received");
         }
     
         public void HandleInterstitialLeftApplication(object sender, EventArgs args)
         {
             print("HandleInterstitialLeftApplication event received");
         }
     
         #endregion
     }

I have actually a problem that after loading the banner and reset the scene banner live. People in the network decides it this way:

 void OnDestroy() {
             bannerView.Destroy();
         }

And it works in most cases, but there are times when the scene is very fast (2-3sekundy example), here's what happens:

1. Requesting Banner 2. Play the scene quickly 3. Try removing OnDestroy () banner that has not load 4. The scene is loaded or reloaded another 5. And only on new scene banner load and banner can't be deleted.

I thought that the banner that any object on the stage to create a new (to then destroy the title), but I did Checker objects in the scene and it showed that no new objects are created. As the banner is displayed, I do not understand.

And I need to be sure it somehow destroy on a new scene. Or to a new banner on the scene is not loading.

But even though the exact same scene, but reloaded scene attempts to remove the banner failed.

There will be complemented by the fact that here in the script from the example, if 2 times to request "RequestBanner ();", the banner will come out 2 - the second over the first and then call the bannerView.Destroy (); - Even repeatedly call, remove only the second banner, the first and continue to hang. If i'm try bannerView.Destroy ();, banner first live continue (((

How can you do?

Specialists, saves the day. Help... Help...Help..

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ekta-Mehta-D · Aug 21, 2015 at 01:11 PM

hii..

  public void HandleAdLoaded(object sender, EventArgs args)
          {
              print("HandleAdLoaded event received.");
              if(Application.loadedLevel == 1) // scene that you want to show ad
              {
                       bannerView.Show();
              }
              else
              {
                      //destroy ad
                      bannerView.Destroy();
              }
          }

You can try this. This may work. Thanks.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Maestro Beginner · Aug 21, 2015 at 01:52 PM 0
Share

thanks.. I will try. but i think this don't be work. because this is reload scene, and when scene reload,and banner called from pre-reload scene, "bannerView.Destroy();" don't destroy banner.

(((

avatar image
0

Answer by nifeho · Apr 02, 2017 at 09:54 AM

I've had this issue as well. The Revmob standard advertisements worked while I was utilizing Unity 4.3, yet they quit working when I refreshed to Unity 4.5, which I expect is what you're utilizing.

Simply take after the directions they've put in the remarks in the show document as though you were utilizing Unity 4.2.2 or underneath (as such, have the "ForwardNativeEventsToDalvik" line in the UnityPlayerNativeActivity area rather than the UnityPlayerProxyActivity segment), and I think it ought to work fine - that is the thing that worked for me at any rate. (I've officially kept in touch with Revmob to propose refreshing their documentation.) pest control services

I'd likewise recommend that on the off chance that you redesign Unity sooner or later, ensure your promotions still work, and if not, the main thing to attempt will be to have a go at moving the "ForwardNativeEventsToDalvik" to an alternate area.

https://community.hortonworks.com/questions/89225/parseexception-while-trying-to-execute-a-show-view.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by rihossain · Oct 07, 2017 at 06:21 AM

This is looking so good solution from Ekta Mehta. pest control services

public void HandleAdLoaded(object sender, EventArgs args) { print("HandleAdLoaded event received."); if(Application.loadedLevel == 1) // scene that you want to show ad { bannerView.Show(); } else { //destroy ad bannerView.Destroy(); } }

I have agree with this . Please tray.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Sorinu · Feb 02, 2019 at 05:55 PM

Tried Ekta Mehta method and not working on android...i can`t realy destroy the banner ...only for 2 sec and then is back. I`ve also added hide and not working. Here is the script that i`ve tried

private BannerView bannerView;

 public void HideBanner(){
 
     {
         bannerView.Hide();
     }
 }


   

public void DestroyBannerView(){ if (this.bannerView != null) { this.bannerView.Destroy(); } } void Start () {

     MobileAds.Initialize(AppID);

     bannerView = new BannerView(BannerAdUnitID, AdSize.Banner, AdPosition.Top);
     bannerView.LoadAd(new AdRequest.Builder().Build());
 }


   public void HandleAdLoaded(object sender, EventArgs args)
       {
           print("HandleAdLoaded event received.");
           if(Application.loadedLevel == 11) // scene that you want to show ad
           {
                    bannerView.Show();
           }
           else
           {
                   //destroy ad
                   bannerView.Destroy();
           }
       }



 void OnDestroy(){
 bannerView.Destroy();

}

void OnHide(){ bannerView.Hide();

} public void DestroyBanner(){

     {
         bannerView.Destroy();
     }
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Admob smartBanner height issue in iphone (ios v9.3) 0 Answers

[Admob] Hiding Banner instantly 1 Answer

iOS Build crashing dyld: Symbol not found 2 Answers

Game crashes when calling RequestBanner() AdMob on iphone 6 0 Answers

bannerView.Destroy(); is not working...the banner still appears after 2 sec 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges