I'm trying to use the new .backgroundTask modifier announced at WWDC '22 but I can't get the below to compile? Xcode says Cannot infer contextual base in reference to member 'appRefresh'
How can I do this?
import SwiftUI
import Foundation
import BackgroundTasks
var body: some Scene {
WindowGroup {
if #available(iOS 16, *) {
AppRootView()
.backgroundTask(.appRefresh("refreshAllData")) {
refreshData()
}
} else {
AppRootView()
}
}
}
Edit: as agentBilly said .backgroundTask is a scene modifier, so should look like this but I'm still unsure how to check for iOS 16 availability?
import SwiftUI
import Foundation
import BackgroundTasks
@main
struct myApp: App {
@Environment(\.scenePhase) var scenePhase
var body: some Scene {
WindowGroup {
AppRootView()
}
.backgroundTask(.appRefresh("refreshAllData")) {
refreshAllData()
}
}