{"id":6097,"date":"2022-06-16T16:54:28","date_gmt":"2022-06-16T08:54:28","guid":{"rendered":"http:\/\/123.57.164.21\/?p=6097"},"modified":"2022-06-16T16:54:28","modified_gmt":"2022-06-16T08:54:28","slug":"swift-ios-app-%e8%ae%be%e5%ae%9a%e4%b8%8d%e4%bc%91%e7%9c%a0","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=6097","title":{"rendered":"Swift iOS APP \u8bbe\u5b9a\u4e0d\u4f11\u7720"},"content":{"rendered":"\n<p>\u901a\u8fc7 UIApplication.shared.isIdleTimerDisabled \u6765\u63a7\u5236<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class SceneDelegate: UIResponder, UIWindowSceneDelegate, CLLocationManagerDelegate {\n\n    var window: UIWindow?\n\n\n    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {\n\n        \/\/ Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.\n        \/\/ If using a storyboard, the `window` property will automatically be initialized and attached to the scene.\n        \/\/ This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).\n\n        \/\/ Get the managed object context from the shared persistent container.\n        let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext\n\n        \/\/ Create the SwiftUI view and set the context as the value for the managedObjectContext environment keyPath.\n        \/\/ Add `@Environme\u222bnt(\\.managedObjectContext)` in the views that will need the context.\n        let contentView = ContentView().environment(\\.managedObjectContext, context)\n\n        \/\/ Use a UIHostingController as window root view controller.\n        if let windowScene = scene as? UIWindowScene {\n            let window = UIWindow(windowScene: windowScene)\n            window.rootViewController = UIHostingController(rootView: contentView)\n            self.window = window\n            window.makeKeyAndVisible()\n        }\n    }\n\n    func sceneDidDisconnect(_ scene: UIScene) {\n        \/\/ Called as the scene is being released by the system.\n        \/\/ This occurs shortly after the scene enters the background, or when its session is discarded.\n        \/\/ Release any resources associated with this scene that can be re-created the next time the scene connects.\n        \/\/ The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).\n    }\n\n    func sceneDidBecomeActive(_ scene: UIScene) {\n        \/\/ Called when the scene has moved from an inactive state to an active state.\n        \/\/ Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.\n        UIApplication.shared.isIdleTimerDisabled = true\n    }\n\n    func sceneWillResignActive(_ scene: UIScene) {\n        \/\/ Called when the scene will move from an active state to an inactive state.\n        \/\/ This may occur due to temporary interruptions (ex. an incoming phone call).\n    }\n\n    func sceneWillEnterForeground(_ scene: UIScene) {\n        \/\/ Called as the scene transitions from the background to the foreground.\n        \/\/ Use this method to undo the changes made on entering the background.\n    }\n\n    func sceneDidEnterBackground(_ scene: UIScene) {\n        \/\/ Called as the scene transitions from the foreground to the background.\n        \/\/ Use this method to save data, release shared resources, and store enough scene-specific state information\n        \/\/ to restore the scene back to its current state.\n\n        \/\/ Save changes in the application's managed object context when the application transitions to the background.\n        (UIApplication.shared.delegate as? AppDelegate)?.saveContext()\n        UIApplication.shared.isIdleTimerDisabled = false\n    }\n\n\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7 UIApplication.shared.isIdleTimerDisabled \u6765\u63a7\u5236<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6097"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6097"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6097\/revisions"}],"predecessor-version":[{"id":6098,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6097\/revisions\/6098"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}