Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 4.6/5.0 Windows Phone 8.1 App - Unable to interact with Microsoft Adverstising Banner

Discussion in 'Windows' started by plasticYoda, Apr 9, 2015.

  1. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    This seems to have been a problem for some time. From what I can see it's pretty much a show stopper for using MS Advertising on their own phone platform.

    The bug was reported, and was marked as 'to be fixed in future version' - I just upgraded my project to Unity 5 and it didnt help - still unable to tap on an Ad and have it expand/interact.

    http://issuetracker.unity3d.com/iss...ot-open-clicked-ads-on-unity-wp8-dot-1-builds

    Can I get an update on this?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,627
    The problem is that right now in generated solution we're creating instance of MainPage and set it as content.
    The solution is to create a Frame, set it as content and then navigate to MainPage. This requires to change quite a bit in generated solution in order to initialize Unity, but after you do, MS Ads will work as well.
     
  3. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    Thanks for the response -- I'll explore that and see if I can get it to work
     
  4. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    Aurimas - after some trial & error and help from another Win C# coder, I was able to get it to work. I'm posting what I did here, so you can verify (I've verified that the changes allow the ads to be tapped) and perhaps spot anything I missed. In addition, this might be useful for people who run into this same problem:

    In MainPage.xaml.cs added the following line after the private declarations at the top of the MainPage class:

    public static MainPage Current { get; private set; }

    With the constructor MainPage remove the SplashScreen parameter

    public MainPage() //SplashScreen splashScreen)

    As we're going to navigate to this page, the OnNavigate method pulls the splashScreen parameter for us, so we can safely remove it from the constructor.

    In App.xaml.cs in InitializeUnity inside the block "if (rootFrame == null && !appCallbacks.IsInitialized())" replace the following lines:

    var mainPage = new MainPage(splashScreen);
    Window.Current.Content = mainPage;


    with:

    rootFrame = new Frame();
    Window.Current.Content = rootFrame;
    if (!rootFrame.Navigate(typeof(MainPage), splashScreen))
    throw new Exception("Failed to navigate to MainPage");


    (The throw is in to catch any errors with the navigate call, it's not really needed)

    In the function RemoveSpashScreen() replace

    MainPage page = (MainPage)Window.Current.Content;

    with

    MainPage.Current.RemoveSplashScreen();


    With these changes, you should be able to tap on the MS Ad content overlaying your Unity App on Windows Phone 8.1
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,627
    Yes, that looks correct.
     
  6. Athomield3D

    Athomield3D

    Joined:
    Aug 29, 2012
    Posts:
    193
    still the appCallbacks.SetSwapChainPanel(mainPage.GetSwapChainPanel());
    giving an error. And using the static version throws a NullReferenceException
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,658
    Athomield3D likes this.