Rev 17 | Rev 19 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// twogetskillsApp.swift// twogetskills//// Created by Efrain Yanez Recanatini on 1/12/22.//import SwiftUIimport BackgroundTasks@mainstruct TwoGetSkillsApp: App {@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate@Environment(\.scenePhase) var scenePhase@ObservedObject var syncForeground = SyncForegroundObservableObject()private let syncAdapter = SyncAdapter()private var appData = AppData.sharedInstanceinit() {let coloredAppearance = UINavigationBarAppearance()coloredAppearance.configureWithOpaqueBackground()coloredAppearance.backgroundColor = UIColor(Color("color_app_bar_backgroud"))coloredAppearance.titleTextAttributes = [.foregroundColor: Color("color_app_bar_foreground")]coloredAppearance.largeTitleTextAttributes = [.foregroundColor: Color("color_app_bar_foreground")]coloredAppearance.backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: Color("color_app_bar_foreground")]UINavigationBar.appearance().standardAppearance = coloredAppearanceUINavigationBar.appearance().compactAppearance = coloredAppearanceUINavigationBar.appearance().scrollEdgeAppearance = coloredAppearanceUINavigationBar.appearance().tintColor = UIColor(Color("color_app_bar_foreground"))UIPageControl.appearance().currentPageIndicatorTintColor = .systemBlueUIPageControl.appearance().pageIndicatorTintColor = .systemGray2if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {let fileURL = dir.appendingPathComponent(Config.DEVICE_UUID_FILENAME)if !FileManager.default.fileExists(atPath: fileURL.path) {if appData.deviceUuid.isEmpty {if let new_uuid = UIDevice.current.identifierForVendor?.uuidString {do {try new_uuid.write(to: fileURL, atomically: false, encoding: .utf8)var sync = SyncModel()sync.data = new_uuidsync.type = Constants.SYNC_ADAPTER_TYPE_DEVICElet syncDao = SyncDao()if syncDao.insert(record: sync) > 0 {appData.deviceUuid = new_uuidappData.save()let syncAdapter = SyncAdapter()syncAdapter.sync(isForeground: true) {success in}}}catch {/* error handling here */}}} else {do {try appData.deviceUuid.write(to: fileURL, atomically: false, encoding: .utf8)}catch {/* error handling here */}}}}}var body: some Scene {WindowGroup {MainView()}.onChange(of: scenePhase) { newScenePhase inswitch newScenePhase {case .active:print("App is active")syncForeground.timer.invalidate()syncForeground.timer = Timer.scheduledTimer(timeInterval: 30.0, target: syncAdapter, selector: #selector(syncAdapter.updateTimerForeground), userInfo: nil, repeats: true)breakcase .inactive:print("App is inactive")syncForeground.timer.invalidate()breakcase .background:print("App is in background")syncForeground.timer.invalidate()break@unknown default:print("Oh - interesting: I received an unexpected new value.")syncForeground.timer.invalidate()break}}}}class SyncForegroundObservableObject: ObservableObject{@Published var timer : Timer = Timer()}