1

My application is a UIKit app (Swift + Objective-C), not a SwiftUI app. After implementing this new WidgetKit how can I perform deeplink from widget to my app?

Which method in AppDelegate I will get the callback?

Check the code below:

var body: some View {
    VStack {
        Text(entry.date, style: .time)
            .widgetURL(widgetsEntryView.deeplinkURL)
    }
}

If I create the project in Swift then I am getting the callback on:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {

}

Tried Link also. Can someone help me to solve this.

koen
  • 5,383
  • 7
  • 50
  • 89
Ajith Kumar
  • 1,202
  • 1
  • 10
  • 22
  • Does this answer your question? [Perform a deeplink from SwiftUI widget on tap](https://stackoverflow.com/questions/64230355/perform-a-deeplink-from-swiftui-widget-on-tap) – pawello2222 Nov 17 '20 at 09:48
  • Specifically this answer: https://stackoverflow.com/a/64297619/8697793 – pawello2222 Nov 17 '20 at 09:49
  • No it doesn't. Objective C call back method is not there. It works fine for me If I use swift and swiftui. Not in Objective c. – Ajith Kumar Nov 17 '20 at 10:18

1 Answers1

3

Which method in AppDelegate I will get the callback?

You can use application:openURL:options:

- (BOOL)application:(UIApplication *)app 
            openURL:(NSURL *)url 
            options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;
pawello2222
  • 46,897
  • 22
  • 145
  • 209
  • Thank you @pawello2222 !! Just wanted to add couple of notes from my own test (**lock screen widget** - small size), containing app is written on Obj-C: **If app in cold state/terminated, _ex: kill the app from xcode_, `openURL :` is not called, nor other related `appDelegate` methods. ** If using `Link` instead of `widgetLink`, `openURL:` is not called, instead both `willContinueUserActivityWithType:` and `continueUserActivity:` are called and `webpageURL` is null – Sam Jul 28 '23 at 13:39