I just added a .systemLarge
widget to my app, but I can't get Link
s to work. I want the user to be able to tap one of the four rows in my widget - like the EmojiRangers example - but I can't get it to work.
I watched a Developer video from WWDC20: https://developer.apple.com/videos/play/wwdc2020/10036?time=223
The guy, Izzy, 'simply' embeds an HStack
in a Link
, and hey presto! It all works. But that doesn't happen for me. There's clearly some code in the background that runs.
I already have .widgetURL
working for .systemSmall
and .systemMedium
widgets, and I don't need to use Link
s on those two types. Those work by sending a URL to .onOpenURL { incomingURL in ...
All good there, no issues.
I've wrapped each row in the large widget in a Link
with the URL of something like myappurlscheme://widgetTapped/widgetId
(it's the same url as that used in the small and medium widgets). I build & run. I tap a row. It doesn't act as though a row is tappable (it doesn't go slightly transparent), and just opens the app without hitting .onOpenURL
or anything else. Nothing in my scene delegate is triggered. Is there a specific delegate method that gets called? Do I need to set up some awful intents?
I'm not using any sort of NavigationStack here; that model doesn't fit my app.
Any ideas? Thanks.
Here's what prints to the log when I run the app:
application: didFinishLaunchingWithOptions
launchOptions =
application: configurationForConnecting
scene: willConnectTo session
maybeOpenedFromWidget(): urlContexts = []
I go to the Home screen, and tap a small widget:
.onOpenURL
url.scheme = Optional("myscheme")
url.path.description = E3C68269-EFB9-44EB-BD6F-430FADD4E6E7
scene: openURLContexts
maybeOpenedFromWidget(): urlContexts = [<UIOpenURLContext: 0x600000365840; URL: myscheme://myhost/E3C68269-EFB9-44EB-BD6F-430FADD4E6E7; options: <UISceneOpenURLOptions: 0x600001805d00; sourceApp: (null); annotation: (null); openInPlace: NO; _eventAttribution: (null)>>]
Launched from widget
I go to the Home screen and tap a medium widget:
url.scheme = Optional("myscheme")
url.path.description = E7B8A9DB-A465-4AD9-99B3-DDCF054712A7
scene: openURLContexts
maybeOpenedFromWidget(): urlContexts = [<UIOpenURLContext: 0x6000002e5960; URL: myscheme://myhost/E7B8A9DB-A465-4AD9-99B3-DDCF054712A7; options: <UISceneOpenURLOptions: 0x600001779540; sourceApp: (null); annotation: (null); openInPlace: NO; _eventAttribution: (null)>>]
Launched from widget
I go to the Home screen and tap a row in the large widget. The row does not go faint like it's supposed to, so the Link
clearly isn't working. Nothing is printed in the log.
EDIT: Oh, I just found out it's yet another bug from Apple ¯\_(ツ)_/¯ Please invest in some automated tests, guys!