{"id":3751,"date":"2021-08-14T15:26:09","date_gmt":"2021-08-14T07:26:09","guid":{"rendered":"http:\/\/123.57.164.21\/?p=3751"},"modified":"2021-08-14T15:26:09","modified_gmt":"2021-08-14T07:26:09","slug":"%e5%a6%82%e4%bd%95%e8%ae%a9apple-watch-app-%e4%bf%9d%e6%8c%81active%e7%8a%b6%e6%80%81","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=3751","title":{"rendered":"\u5982\u4f55\u8ba9Apple Watch App \u4fdd\u6301Active\u72b6\u6001"},"content":{"rendered":"\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/stackoverflow.com\/questions\/47896493\/can-i-keep-a-watch-app-running-in-background\">https:\/\/stackoverflow.com\/questions\/47896493\/can-i-keep-a-watch-app-running-in-background<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5728Apple Watch App \u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u5019\u6211\u4eec\u5e0c\u671bApple Watch App\u80fd\u4e00\u76f4\u8fd0\u884c\u5728\u524d\u53f0\u3002\u4f46\u662f\u5f00\u53d1\u65f6\uff0c\u5982\u679c\u4e0d\u505a\u4ec0\u4e48\u7279\u522b\u5904\u7406\u7684\u8bdd\uff0c\u4f1a\u53d1\u73b0App\u5728\u4e00\u6bb5\u65f6\u95f4\u5c31\u4f1a\u8fdb\u5165\u540e\u53f0\uff0c\u5e76\u4e14\u8868\u76d8\u4f1a\u663e\u793a\u65f6\u95f4\u3002\u90a3\u4e48\u6709\u4ec0\u4e48\u65b9\u6cd5\u80fd\u8ba9App\u4e00\u76f4\u4fdd\u6301\u6d3b\u8dc3\u5462\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528Background Gps\u3002<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/08\/IMG_0104.png\" alt=\"\" class=\"wp-image-3752\" width=\"231\" height=\"282\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/IMG_0104.png 324w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/IMG_0104-247x300.png 247w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/IMG_0104-230x280.png 230w\" sizes=\"(max-width: 231px) 100vw, 231px\" \/><figcaption>App\u53ef\u4ee5\u4e00\u76f4\u8fd0\u884c\u5728\u524d\u53f0<\/figcaption><\/figure><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/08\/IMG_0105.png\" alt=\"\" class=\"wp-image-3753\" width=\"236\" height=\"287\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/IMG_0105.png 324w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/IMG_0105-247x300.png 247w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/IMG_0105-230x280.png 230w\" sizes=\"(max-width: 236px) 100vw, 236px\" \/><figcaption>\u9000\u5230\u8868\u76d8\u65f6\uff0c\u8fd8\u80fd\u770b\u5230App\u8fd0\u884c\u5728\u540e\u53f0<\/figcaption><\/figure><\/div>\n<\/div>\n<\/div>\n\n\n\n<ul><li>Apple Watch\u4e2d\u5f00\u542fBackground Location updates<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-1024x559.png\" alt=\"\" class=\"wp-image-3754\" width=\"746\" height=\"406\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-1024x559.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-300x164.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-768x419.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-1536x839.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-2048x1118.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-830x453.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-350x191.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-42-480x262.png 480w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure><\/div>\n\n\n\n<ul><li>Info.plist\u4e2d\u6dfb\u52a0 Privacy <\/li><\/ul>\n\n\n\n<p>Privacy &#8211; Location Always and When In Use Usage Description<\/p>\n\n\n\n<p>Privacy &#8211; Location Always Usage Description<\/p>\n\n\n\n<p>Privacy &#8211; Location When In Use Usage Description<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-1024x561.png\" alt=\"\" class=\"wp-image-3756\" width=\"676\" height=\"370\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-1024x561.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-300x164.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-768x421.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-1536x841.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-2048x1121.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-830x454.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-350x192.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/08\/\u56fe\u7247-43-480x263.png 480w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><\/figure><\/div>\n\n\n\n<ul><li>\u5728 ExtensionDelegate.swift \u4e2d\u542f\u52a8GPS \u5b9a\u4f4d\u3002<\/li><\/ul>\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=\"\">\n\nimport WatchKit\nimport CoreLocation\n\nclass ExtensionDelegate: NSObject, WKExtensionDelegate, CLLocationManagerDelegate {\n    var locationManager: CLLocationManager?\n\n    func applicationDidFinishLaunching() {\n\n        self.locationManager = CLLocationManager()\n        self.locationManager!.delegate = self\n        self.locationManager!.distanceFilter = 1\n        self.locationManager!.desiredAccuracy = kCLLocationAccuracyBest\n        self.locationManager!.requestAlwaysAuthorization()\n        \/\/ \u8fd9\u4e00\u884c\u4ee3\u7801\u975e\u5e38\u91cd\u8981\uff01\uff01\uff01\n        self.locationManager!.allowsBackgroundLocationUpdates = true\n        self.locationManager!.startUpdatingLocation()\n    }\n\n    func applicationDidBecomeActive() {\n        \/\/ Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.\n    }\n\n    func applicationWillResignActive() {\n        \/\/ Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.\n        \/\/ Use this method to pause ongoing tasks, disable timers, etc.\n    }\n\n    func handle(_ backgroundTasks: Set&lt;WKRefreshBackgroundTask>) {\n        \/\/ Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one.\n        for task in backgroundTasks {\n            \/\/ Use a switch statement to check the task type\n            switch task {\n            case let backgroundTask as WKApplicationRefreshBackgroundTask:\n                \/\/ Be sure to complete the background task once you\u2019re done.\n                backgroundTask.setTaskCompletedWithSnapshot(false)\n            case let snapshotTask as WKSnapshotRefreshBackgroundTask:\n                \/\/ Snapshot tasks have a unique completion call, make sure to set your expiration date\n                snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil)\n            case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask:\n                \/\/ Be sure to complete the connectivity task once you\u2019re done.\n                connectivityTask.setTaskCompletedWithSnapshot(false)\n            case let urlSessionTask as WKURLSessionRefreshBackgroundTask:\n                \/\/ Be sure to complete the URL session task once you\u2019re done.\n                urlSessionTask.setTaskCompletedWithSnapshot(false)\n            case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask:\n                \/\/ Be sure to complete the relevant-shortcut task once you're done.\n                relevantShortcutTask.setTaskCompletedWithSnapshot(false)\n            case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask:\n                \/\/ Be sure to complete the intent-did-run task once you're done.\n                intentDidRunTask.setTaskCompletedWithSnapshot(false)\n            default:\n                \/\/ make sure to complete unhandled task types\n                task.setTaskCompletedWithSnapshot(false)\n            }\n        }\n    }\n\n}\n\nextension ExtensionDelegate: WCSessionDelegate {\n\n\n    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {\n        let currentLocation = locations.last! as CLLocation\n        \n\n    }\n\n    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {\n\n        switch status.rawValue {\n\n        case 0:\n            print(\"Not determined\")\n            NotificationCenter.default.post(name: .gpsInfo, object: \"Not determined\", userInfo: nil)\n\n        case 1:\n            print(\"Restricted Access\")\n            NotificationCenter.default.post(name: .gpsInfo, object: \"Restricted Access\", userInfo: nil)\n\n        case 2:\n            print(\"Denied\")\n            NotificationCenter.default.post(name: .gpsInfo, object: \"Denied\", userInfo: nil)\n\n        case 3:\n            print(\"Authorized Always\")\n            self.locationManager!.requestLocation()\n            NotificationCenter.default.post(name: .gpsInfo, object: \"Authorized Always\", userInfo: nil)\n\n            break\n\n        case 4:\n\n            print(\"Authorization When in use\")\n            self.locationManager!.requestLocation()\n\n        default:\n            break\n        }\n\n    }\n\n    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {\n\n\n    }\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\uff1ahttps:\/\/stackoverflow.com\/questions\/47896493\/can-i-k [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3751"}],"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=3751"}],"version-history":[{"count":4,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3751\/revisions"}],"predecessor-version":[{"id":3759,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3751\/revisions\/3759"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}