{"id":5801,"date":"2022-05-11T10:37:58","date_gmt":"2022-05-11T02:37:58","guid":{"rendered":"http:\/\/123.57.164.21\/?p=5801"},"modified":"2022-05-11T10:37:58","modified_gmt":"2022-05-11T02:37:58","slug":"swift-%e9%ab%98%e5%ba%a6%e8%ae%a1cmaltimeter%e7%9a%84%e4%bd%bf%e7%94%a8%ef%bc%88%e8%8e%b7%e5%8f%96%e8%ae%be%e5%a4%87%e9%ab%98%e5%ba%a6%e5%8f%98%e5%8c%96%e5%80%bc%e3%80%81%e6%b0%94%e5%8e%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=5801","title":{"rendered":"Swift &#8211; \u9ad8\u5ea6\u8ba1CMAltimeter\u7684\u4f7f\u7528\uff08\u83b7\u53d6\u8bbe\u5907\u9ad8\u5ea6\u53d8\u5316\u503c\u3001\u6c14\u538b\uff09"},"content":{"rendered":"\n<p>\u9ad8\u5ea6\u8ba1 <strong>CMAltimeter <\/strong>\u662f <strong>CoreMotion <\/strong>\u6846\u67b6\u4e2d\u7684\u4e00\u4e2a\u529f\u80fd\u7c7b\uff0c\u4e3b\u8981\u7528\u4e8e\u8bb0\u5f55\u8bbe\u5907\u7684\u9ad8\u5ea6\u53d8\u5316\u3002\u672c\u6587\u6f14\u793a\u5b83\u65f6\u5982\u4f55\u4f7f\u7528\u7684\u3002\u00a0<br><strong>1 \u6548\u679c\u56fe<\/strong><\/p>\n\n\n\n<p>\uff081\uff09\u7a0b\u5e8f\u542f\u52a8\u540e\u5148\u5224\u65ad\u8bbe\u5907\u662f\u5426\u652f\u6301\u9ad8\u5ea6\u8ba1\u3002 <\/p>\n\n\n\n<p>\uff082\uff09\u5982\u679c\u652f\u6301\u7684\u8bdd\u5219\u5b9e\u65f6\u83b7\u53d6\u9ad8\u5ea6\u53d8\u5316\u7684\u5dee\u503c\uff08\u76f8\u5bf9\u7a0b\u5e8f\u542f\u52a8\u65f6\u8bbe\u5907\u6700\u5f00\u59cb\u7684\u4f4d\u7f6e\uff09\uff0c\u4ee5\u53ca\u5f53\u524d\u7684\u5927\u6c14\u538b\u5f3a\u503c\u3002<\/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\/2022\/05\/\u56fe\u7247-42-1024x468.png\" alt=\"\" class=\"wp-image-5802\" width=\"565\" height=\"257\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-42-1024x468.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-42-300x137.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-42-768x351.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-42-230x105.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-42-350x160.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-42.png 1246w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/figure><\/div>\n\n\n\n<p><strong>2 \u6837\u4f8b\u5b9e\u73b0<\/strong><\/p>\n\n\n\n<p>\uff081\uff09\u7531\u4e8e\u5b89\u5168\u9650\u5236\uff0c\u9996\u5148\u6211\u4eec\u8981\u5728<strong> info.plist <\/strong>\u6587\u4ef6\u4e2d\u52a0\u5165\u8bbf\u95ee\u7528\u6237\u5065\u5eb7\u548c\u8fd0\u52a8\u4fe1\u606f\u7684\u76f8\u5173\u63cf\u8ff0\u3002<\/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\/2022\/05\/\u56fe\u7247-43-1024x651.png\" alt=\"\" class=\"wp-image-5803\" width=\"503\" height=\"320\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-1024x651.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-300x191.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-768x488.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-830x528.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-230x146.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-350x223.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43-480x305.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-43.png 1060w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><\/figure><\/div>\n\n\n\n<p>\uff082\uff09\u6837\u4f8b\u4ee3\u7801<\/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=\"\">import UIKit\nimport CoreMotion\n \nclass ViewController: UIViewController {\n    \/\/\u7528\u4e8e\u663e\u793a\u5b9e\u65f6\u4fe1\u606f\n    @IBOutlet weak var textView: UITextView!\n     \n    \/\/\u9ad8\u5ea6\u8ba1\u5bf9\u8c61\n    let altimeter = CMAltimeter()\n     \n    override func viewDidLoad() {\n        super.viewDidLoad()\n         \n        \/\/\u5f00\u59cb\u9ad8\u5ea6\u8ba1\u66f4\u65b0\n        startRelativeAltitudeUpdates()\n    }\n     \n    \/\/ \u5f00\u59cb\u83b7\u53d6\u9ad8\u5ea6\u8ba1\u6570\u636e\n    func startRelativeAltitudeUpdates() {\n        \/\/\u5224\u65ad\u8bbe\u5907\u652f\u6301\u60c5\u51b5\n        guard CMAltimeter.isRelativeAltitudeAvailable() else {\n            self.textView.text = \"\\n\u5f53\u524d\u8bbe\u5907\u4e0d\u652f\u6301\u83b7\u53d6\u9ad8\u5ea6\\n\"\n            return\n        }\n         \n        \/\/\u521d\u59cb\u5316\u5e76\u5f00\u59cb\u5b9e\u65f6\u83b7\u53d6\u6570\u636e\n        let queue = OperationQueue.current\n        self.altimeter.startRelativeAltitudeUpdates(to: queue!, withHandler: {\n            (altitudeData, error) in\n            \/\/\u9519\u8bef\u5904\u7406\n            guard error == nil else {\n                print(error!)\n                return\n            }\n             \n            \/\/\u83b7\u53d6\u5404\u4e2a\u6570\u636e\n            var text = \"---\u9ad8\u5ea6\u8ba1\u6570\u636e---\\n\"\n            text += \"\u9ad8\u5ea6\u53d8\u5316: \\(altitudeData!.relativeAltitude) \u7c73\\n\"\n            text += \"\u538b\u529b: \\(altitudeData!.pressure) kPa\\n\"\n            self.textView.text = text\n \n        })\n    }\n     \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9ad8\u5ea6\u8ba1 CMAltimeter \u662f CoreMotion \u6846\u67b6\u4e2d\u7684\u4e00\u4e2a\u529f\u80fd\u7c7b\uff0c\u4e3b\u8981\u7528\u4e8e\u8bb0\u5f55\u8bbe\u5907\u7684\u9ad8\u5ea6\u53d8\u5316\u3002\u672c\u6587 [&hellip;]<\/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\/5801"}],"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=5801"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/5801\/revisions"}],"predecessor-version":[{"id":5804,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/5801\/revisions\/5804"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}