0

How can we add a widget snapshot in "Add Widget" list as I have marked in red below?

Once I create a widget I can see my app available under the list however not able to make it appear as a snapshot or image. Any help will be appreciated.

struct ToDoLockScreenWidget: Widget {
let kind: String = "Lock Screen Widget"
var body: some WidgetConfiguration {
    if #available(iOSApplicationExtension 16.0, *) {
        return StaticConfiguration(kind: kind, provider: Provider()) { entry in
            ToDoLockScreenWidgetView(entry: entry)
                .widgetURL(URL(string: WidgetURL.lockScreenWidget))
        }
        .supportedFamilies([.accessoryCircular])
        
    } else {
        // Fallback on earlier versions
        return EmptyWidgetConfiguration()
    }

}

thank you. enter image description here

Meluha
  • 1,476
  • 1
  • 9
  • 12
  • Have you implemented the TimelineProvider? Lock Screen widgets are not any different than Home Screen widgets in this regard. Also, you don't need a fall back in your `if #available`. You can't use a Lock Screen widget pre-iOS 16 – Yrb Oct 01 '22 at 19:01
  • Yes, you are right.. there is not much change while adding widgets either to lock screen or home screen.. however, showing snapshot directly to "Widget Gallery" I think there would be something more we need to do..which I am not able to figure out – Meluha Oct 03 '22 at 06:47
  • That is the same as well. Just set up your timeline provider as for any other widget, so you need `func getSnapshot(in context: completion:)`, `getTimeline(in context: completion:)`, `func previewEntry() -> Entry` and that you have the loc screen widgets as supported. Remember, if you do not have a minimum OS version of 16, you need to use `if #available` to add the support. As long as your widget works, the system will show you widget with current data, if available, otherwise with the preview data. – Yrb Oct 03 '22 at 17:54
  • @Yrb I am able to get the lock screen widget, there is no problem. note that I can see it as part of the widget list..However, as shown in the above image I want to see it as a snapshot/preview in the "Widget Gallery".. – Meluha Oct 04 '22 at 12:51
  • 1
    Do you mean at the top of the "Add Widgets" screen? That is Apple that determines that. I suspect based on how often the App is used. Otherwise, you have to scroll to see the app and then choose the Lock Screen widget there. – Yrb Oct 04 '22 at 17:47
  • oh okay.. if that's the case I don't have to worry.. thank you for the info.. – Meluha Oct 05 '22 at 07:17

0 Answers0