0

I have an iOS14 widget that I want to deep link to a screen in my (React-Native) app.

I've set up the deep link on the app side and I can open the desired screen from safari when testing.

example link: myapp://detail/123

AppDelegate.m is set up like so:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  
  if([url.scheme hasPrefix:@"myapp"]) {
    return [RCTLinkingManager application:application openURL:url options:options];
  }
  ...
}

...then I have a working receiver in the RN code that uses Linking to process the URL. All good.

The issue is that when I trigger the link on my widget it opens the app but doesn't go via AppDelegate and so the link isn't processed.

var body: some View {
    ZStack(alignment: .topLeading) {
        ...
    }
    .widgetURL(URL(string: "myapp://detail/\(myIdValue)"))
}

I've added the value myapp to the URLScheme value in my main app's info.plist and then the URL Types > URL Identifier value in my widget's info.plist.

I'm probably missing something obvious here but does anyone know where I'm going wrong?

pawello2222
  • 46,897
  • 22
  • 145
  • 209
scgough
  • 5,099
  • 3
  • 30
  • 48

2 Answers2

2

Don’t gives direct widget URL to parent view. Use subview. Like this.

var body: some View {

 ZStack(alignment: .topLeading) {
    ZStack(alignment: .topLeading) {
        
    }
    .widgetURL(URL(string: "myapp://detail/\(myIdValue)"))
}
}

Also, use Link for medium and large size widget.

var body: some View { 
    Link(destination: "myapp://detail/(myIdValue)") { 
       ZStack(alignment: .topLeading) { ... } 
  } 
}
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52
0

Does your app support multiple scenes? If so, you need to implement scene(_:openURLContexts:) in your scene delegate instead of your app delegate.

Adam
  • 4,405
  • 16
  • 23