diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index 2978c678949..1301508baee 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -346,7 +346,11 @@ public class BrowserViewController: UIViewController { } } - self.feedDataSource.ads = rewards.ads + self.feedDataSource.getAdsAPI = { + // The ads object gets re-recreated when shutdown, so we need to make sure News fetches it out of + // the BraveRewards container + return rewards.ads + } // Observer watching tab information is sent by another device openTabsModelStateListener = braveCore.sendTabAPI.add( diff --git a/Sources/BraveNews/Composer/FeedDataSource.swift b/Sources/BraveNews/Composer/FeedDataSource.swift index feb9b076d7c..aa5963c28d8 100644 --- a/Sources/BraveNews/Composer/FeedDataSource.swift +++ b/Sources/BraveNews/Composer/FeedDataSource.swift @@ -106,7 +106,7 @@ public class FeedDataSource: ObservableObject { } /// An ads object to handle inserting Inline Content Ads within the Brave News sequence - public var ads: BraveAds? + public var getAdsAPI: (() -> BraveAds)? public var historyAPI: BraveHistoryAPI? private let todayQueue = DispatchQueue(label: "com.brave.today") @@ -939,7 +939,7 @@ public class FeedDataSource: ObservableObject { followedSources: followedSources, hiddenSources: hiddenSources, followedChannels: followedChannels.mapValues(Set.init), - ads: ads + ads: getAdsAPI?() ) // Move to OSSignposter when we're 15+ let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "com.brave.ios", category: "Brave News") diff --git a/Sources/BraveNews/Customize/NewsSettingsView.swift b/Sources/BraveNews/Customize/NewsSettingsView.swift index 43c544a33f5..15f381873cd 100644 --- a/Sources/BraveNews/Customize/NewsSettingsView.swift +++ b/Sources/BraveNews/Customize/NewsSettingsView.swift @@ -271,7 +271,7 @@ public struct NewsSettingsView: View { OptInView { @MainActor in Preferences.BraveNews.isShowingOptIn.value = false // Initialize ads if it hasn't already been done - await dataSource.ads?.initialize() + await dataSource.getAdsAPI?().initialize() if dataSource.isSourcesExpired { await withCheckedContinuation { c in dataSource.load {