Application.OpenURL not working in build

Is Application.OpenURL supported for visionOS? It works properly in the editor, but it fails to do anything in the build version.

Thanks for letting us know. We’re on it.

I just encountered this with the log in Xcode saying:

Operation OpenURL is not supported on this platform

Is this feature coming or has it been decided not to support it?

Until this is supported, you can simply place a .mm file in Plugins/iOS with the following contents:

#include <os/proc.h>

extern "C"
{
    void OpenUrl(const char *url) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]] options:[NSDictionary new] completionHandler:nil];
    }
}

Then in a .cs file define the following method:

    public static class OpenUrlHelper
    {
#if UNITY_VISIONOS
        [DllImport("__Internal")]
        public static extern void OpenUrl(string url);
#else
        public static void OpenUrl(string url)
        {
            Application.OpenURL(url);
        }
#endif
    }

And call it using:

OpenUrlHelper.OpenUrl("https://duckduckgo.com");
5 Likes

Thank you very much @da_sxr :slight_smile:

Hi @mtschoen ,

I’ve tried using Application.OpenURL in Unity 2022.3.19f1, but it seems it’s still not functioning as expected. Could you let us know if there are any updates or an estimated timeline for this issue to be resolved?

Thanks,

Thanks for sharing this! Had a legit need for it today. :slight_smile:

Hm… I could swear we landed a fix for this. I’ll investigate and report back.

OK my mistake here. The fix is in review but didn’t make it into 2022.3.19. Should be available in the next patch, though.

2 Likes

Thank you for the quick response and the update. Eagerly waiting for the next patch!

Best,

@da_sxr, could you please provide more explicit instructions on creating this plugin to handle URLs on visionOS? We’re about to deploy an app, and this URL issue doesn’t allow us to do it; we cannot wait for the next Unity update - it seems like it’s not coming this week.

Please specify where exactly to create the objective-C script in Xcode? There’s no such place as “Plugins/iOS”. What’s the complete script?

I put your C# code in Unity; it gives errors I cannot solve. Could you please ensure it’s working in Unity, and if it does, what’s a step-by-step instruction? I know how to implement OpenURL in my scripts. But everything before that point in your instruction is vague, and your script is incomplete again.

What’s the order of implementing these scripts? First, build in Unity with C# scripts, then open the project in Xcode and add the objective-C script?

Thank you so much for your help.

Hey @nikitashokhov!

The Plugins/iOS is a folder you need to create in your Unity project. Then place the .mm content in a file in that folder and it should be automatically included in your Xcode project.

Hey @da_sxr
It works great on the device. Thank you.

Application.OpenURL is still not working in Unity 2022.3.20f1.

displaying the error “Operation OpenURL is not supported on this platform” in the log.

Yeah… unfortunately it didn’t quite make the cut for 2022.3.20. Sorry about that. It should definitely be in for 2022.3.21.

1 Like

Understood, I’ll look forward to 2022.3.21 then.

Regarding the openurlplugin.mm file. I had to select it in the project hierarchy and click VisionOS, so that it would be included in the VisionOS build.

1 Like

I’ve confirmed the fix is included in 2022.3.21f1. Thank you for resolving this in the latest release.

2 Likes

@da_sxr workaround works great in Mixed Reality mode, but it doesn’t work in VR application. Device opens Safari app, but my application crashes.
@mtschoen did you check if OpenURL which will be available in 2022.3.21 works in VR app?

Yeah I’m pretty sure I tested this. Are you having trouble?