As you suggested I have added only two timeline entries but still the widget is not getting auto refreshed.
func getTimeline(in context: Context, completion: @escaping (Timeline<RecommendedWidgetEntry>) -> Void) {
let accessTokenValue = Keychain.getAccessTokenValue()
if let token = accessTokenValue, !token.isEmpty {
widgetVM.getRecommendedDataForWidget{ (result) in
switch result {
case .success(let items):
widgetVM.downloadImages(recommendedData: items) { (result) in
switch result {
case .success(_),.failure(_) :
var refreshEntries: [RecommendedWidgetEntry] = []
if let At6AM = Calendar.current.date(bySettingHour: 6, minute: 0, second: 0, of: Date()) {
let refreshEntryFor6AM = RecommendedWidgetEntry(date: At6AM, recommedationData: items)
refreshEntries.append(refreshEntryFor6AM)
}
if let At6PM = Calendar.current.date(bySettingHour: 18, minute: 0, second: 0, of: Date()) {
let refreshEntryFor6PM = RecommendedWidgetEntry(date: At6PM, recommedationData: items)
refreshEntries.append(refreshEntryFor6PM)
}
let timeline = Timeline(entries: refreshEntries, policy: .atEnd)
completion(timeline)
}
}
case .failure(_):
let entry = RecommendedWidgetEntry(date: Date(), recommedationData: WidgetFeedModel.getPlaceholderData())
let timeline = Timeline(entries: [entry], policy: .never)
completion(timeline)
}
}
}
else {
if accessTokenValue == nil { // if token is nil then considering it as member is not logged in.
SharedContentConstants.clearUserDefaultsData()
let entry = RecommendedWidgetEntry(date: Date(), recommedationData: [])
let timeline = Timeline(entries: [entry], policy: .never)
completion(timeline)
return
}
}
}
On my timeline provider am calling the Rest API to fetch the data to update the widget.
Could you please help me out is there any issue with the refresh policy ( My widgets must auto refresh twice a day like 6AM and 6PM)
Kindly provide the reason, why the widgets are not autorefreshing on it's own.
Thanks.