Launch App with Custom URL Scheme and receive parameters

I am trying to launch an app from Safari using a Custom URL Scheme and obtain the parameters specified in the URL.

In Window mode, the app was able to launch and retrieve the parameters. However, in Poly Spatial (Bounded/Unbounded), the app launches but couldn’t receive the parameters.

If anyone has tried something similar, I would appreciate any information.

I am trying this by creating a plugin based on the implementation found here:

I solved this by taking the URL in SwiftUI and communicating it to the Unity layer.

Here is my solution

  1. Registration of URL Scheme Go to Project Settings > Player > ‘iOS’ tab > Other Settings > Configuration. Change the size of ‘Supported URL Scheme’ to 1 and input any desired URL Scheme into Element 0.
    *This item does not exist in Vision OS, but when entered on the iOS side, it was reflected.

  2. Add onOpenURL() to PolySpatialContentViewWrapper
    Modify the com.unity.polyspatial.visionos package so that the addition of .onOpenURL is reflected in UnityVisionOSSettings.swift.

Path:
MyProject/Library/PackageCache/com.unity.polyspatial.visionos@0.4.3/Editor/VisionOSBuildProcessor.cs

{windowType}(id: ""{configName}"", for: UUID.self) {{ uuid in
    PolySpatialContentViewWrapper()
        .environment(\.pslWindow, PolySpatialWindow(uuid.wrappedValue, ""{configName}"", {dimsVec3}))
        .onOpenURL(perform: {{ url in
                  NSLog(url.absoluteString)
                  // Code to convey url to Unity Layer
                }})
}} defaultValue: {{ UUID() }} {windowStyle}

While I was able to resolve the issue with this approach, I still have some reservations and concerns.

Will the addition of ‘Supported URL Scheme’ also be made to Vision OS in the future?

And,this solution requires changes to the com.unity.polyspatial.visionos package. Is there a better method?

I hope to receive guidance on this matter.

I have sent a request to the Feedback Portal regarding this issue.

https://portal.productboard.com/rfzqiectsg6bhr7v8sewj6xt/tabs/240-under-consideration

Upon investigation, I found that PolySpatial does not use NotificationCenter for onOpenURL notification as expected when executing Custom URL Scheme.

In Window mode, the following methods are called, and finally AppController_SendNotificationWithArg method notifies Observers of onOpenURL using NSNotificationCenter.

Classes/UnityAppController.mm

- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options`

Therefore, even though the Observer is registered in the AppDelegateListener.mm, it is not possible to receive the onOpenURL notification.

So I have made the following modifications to address this issue

MyProject/Library/PackageCache/com.unity.polyspatial.visionos@0.4.3/Editor/VisionOSBuildProcessor.cs

{windowType}(id: ""{configName}"", for: UUID.self) {{ uuid in
    PolySpatialContentViewWrapper()
        .environment(\.pslWindow, PolySpatialWindow(uuid.wrappedValue, ""{configName}"", {dimsVec3}))
        .onOpenURL(perform: {{ url in
                    let data: [String:Any] = [""url"":url]
                    NotificationCenter.default.post(name: NSNotification.Name(""kUnityOnOpenURL""), object: nil, userInfo: data)
                }})
}} defaultValue: {{ UUID() }} {windowStyle}

I’d like to confirm the following:

  1. In Poly Spatial, is it the correct behavior not to send notifications to the Observer registered in AppDelegateListener.mm?
  2. If so, is there a better way to receive notifications?

I have confirmed that this issue has been fixed in Unity2022.3.27f1.

The following code now works:

        private void Awake()
        {
            Application.deepLinkActivated += (urlString) =>
            {
                 // Process the custom URL
            };
        }

Thanks for the fix!

1 Like