Summary
When a SwiftUI widget uses a Link
containing an Image
modified with .widgetAccentedRenderingMode
(using any mode except .fullColor
), tapping the image on the widget launches the app but does not pass the expected deep link URL to the SceneDelegate
.
Steps to Reproduce
-
Create a SwiftUI Widget View with a Link:
struct ImageView: View { var image: UIImage var body: some View { Link(URL(string: "myapp://image")!) { Image(uiImage: image) .resizable() .widgetAccentedRenderingMode(.accentedDesaturated) // or any mode other than .fullColor .scaledToFill() .clipped() } } }
-
Add Custom URL Scheme in
Info.plist
:<dict> <key>CFBundleURLName</key> <string>com.company.myapp</string> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict>
-
Implement Deep Link Handling in
SceneDelegate
:func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { if let url = connectionOptions.urlContexts.first?.url { handle(url) } } func scene(_ scene: UIScene, openURLContexts urlContexts: Set<UIOpenURLContext>) { if let url = urlContexts.first?.url { handle(url) } } private func handle(_ url: URL) { // Process URL here }
-
Run the application on a device or simulator.
-
Add the widget to the Home Screen.
-
Tap the image inside the widget.
Expected Result
The application launches and receives the URL in SceneDelegate
, as expected.
Actual Result
The application launches, but the URL is not passed to SceneDelegate
.
Both connectionOptions.urlContexts
and openURLContexts
are empty.