0

How to pass UIkit data in to widget extension and also get data in widget from User Default?

Second question is I have show dummy data in widget but getTimeline function only show first timeline other timelines not showing?

func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {

    let data = ["One","Two","Three","Four"]

    var entries: [SimpleEntry] = []

    let currentDate = Date()
    for i in 0 ..< data.count {
        let entryDate = Calendar.current.date(byAdding: .minute, value: 60, to: currentDate)!
        let entry = SimpleEntry(date: entryDate, loadEntry: 1, message: data[i])
        entries.append(entry)
    }
    let timeline = Timeline(entries: entries, policy: .atEnd)
    completion(timeline)
}
de.
  • 7,068
  • 3
  • 40
  • 69

1 Answers1

0

Apps and app extensions basically have different containers.
Therefore, internal data such as userdefault and coredata are not shared with each other.
However, there is a way to enable data sharing.

After you enable app groups, an app extension and its containing app can both use the NSUserDefaults API to share access to user preferences.

You can refer to the app extension guide for more information.

And I attach a link that seems to help you with your work.

kyeahen
  • 161
  • 8
  • Link only answers are not allowed. If there is relevant code in the links please share that code. Links get broken over time – lorem ipsum Jul 26 '21 at 15:14
  • Thank you for your advice. I didn't know the detailed guidelines shortly after I started working on the site. – kyeahen Jul 27 '21 at 03:37