1

I'm looking for a way to launch an OSX app(Standalone) created with Unity from a browser using a custom URL scheme.
After add a custom URL scheme to the Info.plist, I can launch the app successfully.
And I want to know how can I get the arguments passed in the URL.(e.g. URLscheme://iwanttoreadthisdata).
Is there any way to do this?

Doi
  • 11
  • 2

1 Answers1

0

Assuming it's a web GL build, you can find info here: https://answers.unity.com/questions/1285359/how-to-read-url-parameters-from-unity-webgl-build.html

The relevant information references that it's a bit tricky, as they use a JS library to execute in the browser context and extract data as a unity library.

https://github.com/Bunny83/UnityWebExamples/blob/master/Mandelbrot/URLParameters.cs

This looks at normal browser locations, and c# accesses/properties to force the js code to execute as a unity library at runtime. For browser JS code, the URL is window.location.href

And it parses out the data from that string using JS and gives back a dictionary object to unity c# code.

(I understand linking to these might be leading to an external site for answers, but the code is a bit lengthy, and would be redundant to copy/paste other good explanations). Other mods can edit if this is unreasonable.

Richard Duerr
  • 566
  • 8
  • 24
  • Thank you so much for your answer. But my app's platform is Mac OSX Standalone, not WebGL. So I couldn't find solutions from these links. Please give me your advice if you have any ideas. – Doi Feb 01 '21 at 01:15
  • Hmm. Is the custom URL scheme the same idea that macOS associates handlers with apps? EG: how iOS / android can ask you to open a URL with an app. I vaguely remember this in macOS. You might need to look at the interface unity exposes. https://docs.unity3d.com/ScriptReference/Application.html On first glance it seems "absoluteURL"? Otherwise, i am unsure if unity is sent those parameters by the operating system if they aren't included in the url field i mentioned. – Richard Duerr Feb 01 '21 at 17:46
  • Yes, I want to launch my macOS app like as iOS and Android app. By using native plugins(Objective-C++ or JAR), I implement custom URL scheme functions on mobile apps. In the case of my Windows standalone app, I create a reg file and read URL scheme parameters with System.Environment.GetCommandLineArgs() method. Unfortunately, "absoluteURL" is not supported macOS standalone, so do I need native plugins for macOS(.bundle) if implement URL scheme function for macOS? – Doi Feb 03 '21 at 06:05