1

I am attempting to implement a means to open specific pages of my app via iOS 14's widget, but so far my attempt just simply open the app without picking up the full deeplinking URL.

In my main app's SceneDelegate.swift:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    if let item = URLContexts.first {
        print(item.url)
    }
}

In my widget's EntryView:

struct EntryWidgetEntryView : View {
    var entry: Provider.Entry

    var body: some View {
        VStack(alignment: .leading, spacing: 4) {
           
            Link(destination: URL(string: "entry://link1")!, label: {
                Text("Link 1")
            })
            Link(destination: URL(string: "entry://link2")!, label: {
                Text("Link 2")
            })    
        }
    }
}

The above implementation prints "entry://" every single time when I launch my app via the widget. This is regardless whether I tap anywhere on the widget, or on the Text labels, all opens my app and prints "entry://", with the subsequent information (ie link1, link2) missing.

I believe I have setup the info.plist correctly in my main app:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string></string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>entry</string>
            </array>
        </dict>
    </array>
Koh
  • 2,687
  • 1
  • 22
  • 62
  • Are you doing a small widget? The small widget needs to use `widgetURL` and not a `Link` – Claus Jørgensen Oct 03 '20 at 13:40
  • @ClausJørgensen Oh is that so. But using `.widgetURL` would mean that I can't tap on the different labels to launch different page of the app? Anyways my intent is to implement across all sizes of widgets – Koh Oct 03 '20 at 14:37
  • @Koh In small widgets you only have **one** tappable area - the Widget itself. Only medium and large Widgets can detect tapping on labels. – pawello2222 Oct 03 '20 at 15:48
  • @Koh you need to use the [widgetFamily](https://developer.apple.com/documentation/widgetkit/widgetfamily) to determine if it's a small or medium/large widget and then apply different logic for whether to use widgetURL or Link. – Claus Jørgensen Oct 03 '20 at 20:16
  • This might help you: [iOS 14 Widgets: How to create different layouts for each sizes of widgets?](https://stackoverflow.com/questions/63246450/ios-14-widgets-how-to-create-different-layouts-for-each-sizes-of-widgets) – pawello2222 Oct 03 '20 at 22:33
  • @pawello2222 Ah ok, that explains. Thanks so much! – Koh Oct 04 '20 at 03:32

0 Answers0