Widget kit deep link

From my understanding, when tapping the widget link, it can trigger a deeplink that triggers certain screen inside the view. I tried by adding Link to the view, but it does not trigger the deep link. (Just opens the app). Is there anything else I need to make it work? Thanks

Replies

Hi Jun, can you provide a few details?
  • What family (size) widget are you using?

  • Does your app already support deep links?

  • Are you using a SwiftUI App, or a UIApplicationDelegate?

Thanks!
Hi there!
  • What family (size) widget are you using?

-> I tried all 3 sizes (small, medium, large)
  • Does your app already support deep links?

    • > Yes. I can trigger the deep link from terminal (xcrun simctl ---)

  • Are you using a SwiftUI App, or a UIApplicationDelegate?

    • > For the main app, we are using UIApplicationDelegate.


Great,

What family (size) widget are you using?
> I tried all 3 sizes (small, medium, large)

Note that Link will only work in systemMedium and systemLarge, for deep linking from a systemSmall widget, you'll need to use widgetURL: https://developer.apple.com/documentation/swiftui/view/widgeturl(_:)

Does your app already support deep links?
> Yes. I can trigger the deep link from terminal (xcrun simctl ---) Are you using a SwiftUI App, or a UIApplicationDelegate?
> For the main app, we are using UIApplicationDelegate.

When your widget gets tapped your app should be passed the URL, if you support scenes your scene delegate should get a scene(_:openURLContexts:) call, otherwise your application delegate should get a application(_:open:options:) call.
this is helpful to me also ! i was wondering which app delegate (if it was at all gets called) see my post, i believe this answers it too! Thank you @frameworks Engineer :D

https://developer.apple.com/forums/thread/651786


Can you provide an example of how to pass the data from Widget when the main app is using UIApplicationDelegate please?
I've just got .widgetURL working, but how do i work that with a medium or large widget? I can't get a Link working. Its annoying to only be able to have one .widgetURL when my widget has multiple views

Solved: My Link wasn't working inside of my View for some reason, but it worked when I put it around my view

what didnt work:

Code Block
View(){
Link(){
...
}
}
Widget(){
View()
}


what did work:

Code Block
View(){
...
}
Widget(){
Link(){
View()
}
}




@Frameworks Engineer

Please file a radar to ensure that the below is reflected in the docs. It took me a bit too long to find this thread. Thanks!

Note that Link will only work in systemMedium and systemLarge, for deep linking from a systemSmall widget, you'll need to use widgetURL: https://developer.apple.com/documentation/swiftui/view/widgeturl(_:)


@jtepp,

You said,
"I've just got .widgetURL working, but how do i work that with a medium or large widget? I can't get a Link working. Its annoying to only be able to have one .widgetURL when my widget has multiple views

Solved: My Link wasn't working inside of my View for some reason, but it worked when I put it around my view

what didnt work: 

Code Block
View(){ Link(){ ... }}Widget(){ View()}


what did work:

Code Block
View(){ ...}Widget(){ Link(){ View() }}"

Could you actually show the example code? The way you have it doesn't make sense to me. Please?