0

In the old versions of my app, the scene(_:openURLContexts:) method is always called in these two cases:

  1. The app isn't running. Then It's launched by an airdropped file.
  2. The app is already running. Then a file is airdropped.

I created a separate app to work on the new version and made a lot of code changes. None of the changes should affect the above behavior, but I find the case 1 doesn't work. If the app isn't running, the airdropped file launches it successfully, but scene(_:openURLContexts:) isn't called.

More information:

  1. To verify scene(_:openURLContexts:) is really not called, I added logs in the method and used Console app to monitor the logs.

  2. I tested the old app on the same phone, which runs iOS 16.0.2. It works fine in both cases. So this isn't an OS issue.

  3. Both of the apps are SwiftUI apps.

I searched on the net and found this workaround. It works for me.

I've discovered that the code below is need in willConnectTo session:

self.scene(scene, openURLContexts: connectionOptions.urlContexts)

The Apple's doc is very concise on these APIs. It's not clear to me what's the expected behavior and why my two apps have different behavior. Does anyone know if scene(_:openURLContexts:) is expected to be called when when app is launched by an airdropped file?

UPDATE: from this answer, scene(_:openURLContexts:) is not expected to be called when when app is launched by an airdropped file. If so, I don't understand why my old app works (from my search on the net, I'm not the only one who observed the different behaviors).

rayx
  • 1,329
  • 10
  • 23

0 Answers0