Search Unity

Application.OpenURL causing application on WP8 phone to stop

Discussion in 'Windows' started by Memosis, Jul 23, 2013.

  1. Memosis

    Memosis

    Joined:
    Jul 23, 2013
    Posts:
    12
    We call Application.OpenURL when user clicks banner in our game or when we want to display ratings in store. It works on all platforms we used so far (Win x86, Mac, Android, iOS). On WP8 phone the game simply stops. We will appreciate your experience and tips on debugging these kinds of problems.
     
  2. BFS-Kyle

    BFS-Kyle

    Joined:
    Jun 12, 2013
    Posts:
    883
    I believe Application.OpenURL is not yet implemented in WP8, so you can't use it (seems to quit the game when it gets called). You will have to handle this yourself after exporting the build into Visual Studio and then edit the project. There is an example of how to do this in the Windows Phone 8 Beta group if you have access.

    The other alternative is to grab one of the Windows Phone 8 plugins - currently there are two that I know of, one is my own called BFS WP8 Goodies which has functionality to open URL's among other things, and the other is called RobotoWP plugin for Windows Phone which from the looks of it (I haven't purchased this plugin) can also handle opening URL's.

    -Kyle
     
  3. DanielSan

    DanielSan

    Joined:
    Nov 20, 2012
    Posts:
    5
    Create a static class in Unity with a static event...

    Code (csharp):
    1.  
    2. public static class WP8Statics
    3. {
    4.      public static event EventHandler OpenUrlHandle;   
    5.    
    6.      public static void FireOpenUrl(string url)
    7.      {
    8.           if (OpenUrlHandle != null)
    9.           {
    10.                OpenUrlHandle(url, null);           
    11.           }
    12.      }
    13. }
    Build in Unity to create a VS solution. Open the solution and then attach the native browser functionality to the method you created in MainPage.xaml.cs...

    Code (csharp):
    1.  
    2. // Constructor
    3. public MainPage()
    4. {
    5.      ...
    6.      WP8Statics.OpenUrlHandle += WP8Statics_OpenUrlHandle;
    7. }
    8.  
    9. void WP8Statics_OpenUrlHandle(object sender, EventArgs e)
    10. {
    11.        Microsoft.Phone.Tasks.WebBrowserTask wbt = new Microsoft.Phone.Tasks.WebBrowserTask();
    12.        wbt.Uri = new Uri((string)sender);
    13.        wbt.Show();
    14. }
     
    Last edited: Aug 5, 2013
    jdrostov likes this.