Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Application.OpenURL IOS Problem

Discussion in 'iOS and tvOS' started by nshack31, Feb 21, 2012.

  1. nshack31

    nshack31

    Joined:
    Nov 4, 2011
    Posts:
    96
    When trying to open a browser window from Unity it works fine on Android but nothing happens on IOS, is Application.OpenURL compatible? I ran the program it from an iPod touch:

    Code (csharp):
    1. //if its the tweet button
    2.                 if (myhit.collider.name == "tweetButton"){
    3.         #if UNITY_ANDROID
    4.             Application.OpenURL("https://twitter.com/home?status=MY TEST TWEET");
    5.     #endif
    6.                        
    7.             #if UNITY_IPHONE
    8.             Application.OpenURL("https://twitter.com/home?status=MY TEST TWEET");
    9.     #endif
    10.                 }
     
  2. nshack31

    nshack31

    Joined:
    Nov 4, 2011
    Posts:
    96
    i've managed to figure out that the problem is with the spaces in the URL. If i try
    Code (csharp):
    1. Application.OpenURL("https://twitter.com/home?status=TEST");
    it works. So how can I correctly escape the URL? i have tried the following to no avail...

    Code (csharp):
    1. Application.OpenURL(WWW.EscapeURL("https://twitter.com/home?status=TEST MESSAGE"));
     
  3. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Try URL encoding it. This will replace special characters with their URL encoded counterparts (for instance, spaces are replaced with %20). This will probably fix your problem.
     
  4. nshack31

    nshack31

    Joined:
    Nov 4, 2011
    Posts:
    96
  5. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Oh, haha, I didn't notice that in your last example. Yes you should be. I am not sure then, seems like it should work to me.
     
  6. SolInvictus212

    SolInvictus212

    Joined:
    Aug 10, 2011
    Posts:
    50
    I'm having a similar problem. For a simple example, with the following:
    Code (csharp):
    1.  
    2.      Debug.Log("Open URL");
    3.      Application.OpenURL(WWW.EscapeURL("http://www.engadget.com"));
    4.  
    Both in the editor and on the iPhone, "Open URL" is printed to the console, but nothing happens, no url is opened. I tried it both with and without EscapeURL.
    I'm in dire need of help opening a webpage on iPhone, as it's the last major features holding back my current project.
     
    Last edited: Feb 29, 2012
  7. SolInvictus212

    SolInvictus212

    Joined:
    Aug 10, 2011
    Posts:
    50
    Never mind, I fixed my problem.
    Ironically, WWW.EscapeURL somehow breaks it. When I originally tried it without EscapeURL, I forgot the 'http,' so it was just www. Now it works on both iPhone and the Editor.
    To summarize:
    Application.OpenURL(WWW.EscapeURL("http://www.engadget.com")); Did Not Work
    Application.OpenURL("www.engadget.com"); Did Not Work
    Application.OpenURL("http://www.engadget.com"); Worked

    Sorry I don't know what's causing your problem, then, nshack. Maybe iOS has a problem opening https from OpenURL?
     
  8. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    You're using it incorrectly - you normally use WWW.EscapeURL for the parameter values ONLY, not for the entire URL. The way you were doing it, it was encoding the colon and slashes after 'http'.
     
  9. nshack31

    nshack31

    Joined:
    Nov 4, 2011
    Posts:
    96
    thanks. I think my problem was caused by trying to use the Twitter app. If you open the link using the browser it works correctly, but if you try and open it with the app (when prompted) it is rejected... i think this is because OAuth must be setup to send a status to the app
     
  10. xpecttrum

    xpecttrum

    Joined:
    Mar 10, 2014
    Posts:
    5
    Hello, I am having big trouble with Application.openURL

    I tried:

    Application.openURL("https://play.google.com/store/apps/details?id=com.pradolabs.animalpuzzle")

    Application.openURL("market://details?id=com.pradolabs.animalpuzzle")

    Application.openURL("http://play.google.com/store/apps/details?id=com.pradolabs.animalpuzzle")

    It never works, on android, it always starts opening the market, or the browser, and then stall for like 5 minutes then crashes.

    My device is very old, I am not sure if that's the reason, but what I am possibly doing wrong?

    Help please, why Application.OpenURL just do not open the URL for me?

    Do I need to put a sleep after it?

    Thanks.
     
  11. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377
    It seems that Unity removes all arguments from the URL before opening it in the browser.

    So
    https://play.google.com/store/apps/details?id=com.pradolabs.animalpuzzle
    becomes
    https://play.google.com/store/apps/details
    .
     
  12. mohammedghabyen

    mohammedghabyen

    Joined:
    Feb 25, 2019
    Posts:
    18
    I've solved it by shorting links using bitly,
    this is working: Application.OpenURL("http://apple.co/3s3YZIS")
    maybe its the https I am not sure.