Skip to content

bug: iOS ‘appUrlOpen’ event provided by App plugin doesn't work when App is opened from an URL for the first time with SceneDelegate  #2484

@carelliguillaume

Description

@carelliguillaume

Bug Report

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 4.3.0
@capacitor/core: 4.3.0
@capacitor/android: 4.3.0
@capacitor/ios: 4.3.0

Installed Dependencies:

@capacitor/cli: 4.3.0
@capacitor/android: 4.3.0
@capacitor/ios: 4.3.0
@capacitor/core: 4.3.0

[success] iOS looking great! 👌

Platform(s)

iOS (tested on versions: 14, 15, 16)

Current Behavior

When I add the SceneDelegate iOS architecture (needed by Apple CarPlay), ‘appUrlOpen’ event provided by Capacitor App plugin stops working on iOS when App is opened from an URL for the first time. When the App is opened from an URL while the application is in background there is no problem. But when the app is killed and opened for the first time from an URL (URL Scheme or Universal Link) it doesn’t work.

We’ve found a dirty workaround, its a concurrency problem, and the function : "ApplicationDelegateProxy.shared.application(UIApplication.shared, open: url)" is called too early in the iOS SceneDelegate event triggered when the App is started from an URL: "func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {". When it’s called too early, the ApplicationDelegateProxy will not trigger the ‘appUrlOpen’ Capacitor App Plugin event.
But when you delay the call for 0.5 or 1 seconds like I did in comments in SceneDelegate.swift in this sample you will see that the event will trigger with no problems.

When you add a SceneDelegate, the AppDelegate function triggered when application is opened from an URL will not be called :

  • func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

Instead SceneDelegate events replace AppDelegate events with this function :

  • func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

It works with AppDelegate architecture, but with SceneDelegate architecture, it seems to be called too early.

Expected Behavior

The ‘appUrlOpen’ event provided by Capacitor App should work on iOS when the App is opened from an URL (URL Scheme or Universal Link) with SceneDelegate iOS architecture.

Code Reproduction

https://github.com/carelliguillaume/ionic-capacitor-scenedelegate-openurl

This project is an Ionic / Capacitor App with just 1 tab to show the problem.

You just have to open the App from an URL Scheme defined is this sample starting with "ulys.alpha.auth://" with Safari.
If the ‘appUrlOpen’ triggers, you will see an IonToast at startup with the URL and it will print also this URL in IonTextArea on the first tab.

IMG_6497

Other Technical Details

npm --version output: 9.6.6

node --version output: v14.17.6

pod --version output (iOS issues only): 1.11.2

Additional Context

•	iOS Devices used to reproduce the behavior
•	
•	iPhone 14 Pro (iOS 16)
•	iPhone X (iOS 15)
•	iPad Pro 1st Gen (iOS 14)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions