我正在为我的孩子做一个简单的盾牌应用程序,我是斯威夫特的新手,我提前为糟糕的代码道歉。我是从Youtube上的一个教程中学到的。
import Foundation
import FamilyControls
import DeviceActivity
import ManagedSettings
import SwiftUI
extension DeviceActivityName {
static let daily = Self("daily")
}
struct Testing_SwiftUIApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
class MyMonitor: DeviceActivityMonitor {
let store = ManagedSettingsStore()
override func intervalDidStart(for activity: DeviceActivityName) {
self.superBS_Start()
//它返回在范围内找不到MyModel()。
let model = MyModel()
let applications = model.selectionToDiscourage.applications
store.shield.applications = applications?.isEmpty ? nil : applications
}
override func intervalDidEnd(for activity: DeviceActivityName) {
self.superBS_End()
store.shield.applications = nil
}
}
func superBS_Start(){
super.intervalDidStart(for: activity)
}
func superBS_End(){
super.intervalDidEnd(for: activity)
}
let schedule = DeviceActivitySchedule(
intervalStart: DateComponents(hour: 0, minute: 0),
intervalEnd: DateComponents(hour:23, minute: 59),
repeats: true
)
let center = DeviceActivityCenter()
try center.startMonitoring(.daily, during: schedule)
//它返回在范围内找不到MyModel()。
@StateObject var model = MyModel()
@State var isPresented = false
var body: some View {
Button ("Select Apps to Discourage"){
isPresented = true
}
.familyActivityPicker(isPresented: $isPresented,
selection: $model.selectionToDisourage)
}
}
}
我不知道为什么它不在范围内。很抱歉我是斯威夫特的新手。
1条答案
按热度按时间qyswt5oh1#
据我所知,MyModel()是一个自定义类/结构,您应该创建它。我没有看到您创建过任何这样的类或结构。