2

Morning, everyone,

I'm developing a widget using an API that sends an array of different sizes depending on the size of the widget (small : 3 news, medium: 6 news, large: 9 news).

I have the impression that there is a problem between the @Environment(\.widgetFamily) var family and the timeline function (where I call the API) of TimelineProvider.

Indeed in this function the environment variable is always equal to the systemMedium size despite the "real" size of the widget.

Do you also have the same problem on your side ? Is it a known bug from Apple ? How can I solve this bug ?

Thanks for your help :]

2
  • Would you show your code?
    – Asperi
    Aug 4, 2020 at 13:45
  • Basic fetch from API then I do a switch with the three sizes of the widget. But it's always going to the systemMedium size...
    – jackson89
    Aug 4, 2020 at 14:41

1 Answer 1

2

Without seeing your code, my best guess is that you're not accessing the family property of the TimelineProviderContext passed into the TimelineProvider.

Your TimelineProvider should look something like:

struct MyProvider: TimelineProvider {
    func snapshot(with context: Context, completion: @escaping (Entry) -> ()) {
        fetchNewsArticles(for: context.family) { articles in
              // ...
              completion(...)
        }
    }
}

func fetchNewsArticles(for widgetFamily: WidgetFamily, completion: @escaping ... ) 
{
     switch family {
         case .systemSmall:
         // ...
}

Apple Docs - TimelineProvider

Apple Docs - TimelineProviderContext

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.