{"id":3501,"date":"2021-07-16T14:34:58","date_gmt":"2021-07-16T06:34:58","guid":{"rendered":"http:\/\/123.57.164.21\/?p=3501"},"modified":"2021-07-16T14:34:58","modified_gmt":"2021-07-16T06:34:58","slug":"swift-%e5%88%a4%e6%96%ad%e6%98%af%e5%90%a6%e6%9c%89%e6%9f%90%e5%8a%9f%e8%83%bd%e8%ae%bf%e9%97%ae%e6%9d%83%e9%99%90%ef%bc%8c%e6%b2%a1%e6%9c%89%e5%88%99%e6%8f%90%e7%a4%ba%ef%bc%8c%e5%b9%b6%e8%87%aa","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=3501","title":{"rendered":"Swift &#8211; \u5224\u65ad\u662f\u5426\u6709\u67d0\u529f\u80fd\u8bbf\u95ee\u6743\u9650\uff0c\u6ca1\u6709\u5219\u63d0\u793a\uff0c\u5e76\u81ea\u52a8\u8df3\u8f6c\u5230\u8bbe\u7f6e\u9875"},"content":{"rendered":"\n<p>\u7531\u4e8e&nbsp;<strong>iOS&nbsp;<\/strong>\u7cfb\u7edf\u7684\u5b89\u5168\u9650\u5236\uff0c<strong>App&nbsp;<\/strong>\u5982\u679c\u9700\u8981\u8bbf\u95ee\u8bbe\u5907\u7684\u901a\u8baf\u5f55\u3001\u9ea6\u514b\u98ce\u3001 \u76f8\u518c\u3001 \u76f8\u673a\u3001\u5730\u7406\u4f4d\u7f6e\u7b49\u65f6\uff0c\u9700\u8981\u8bf7\u6c42\u7528\u6237\u662f\u5426\u5141\u8bb8\u8bbf\u95ee\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\/2021\/07\/image-71.png\" alt=\"\" class=\"wp-image-3502\" width=\"333\" height=\"369\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-71.png 636w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-71-271x300.png 271w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-71-230x255.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-71-350x387.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-71-480x531.png 480w\" sizes=\"(max-width: 333px) 100vw, 333px\" \/><\/figure><\/div>\n\n\n\n<p>\u6709\u65f6\u7528\u6237\u4e0d\u5c0f\u5fc3\u70b9\u4e86\u201c<strong>\u4e0d\u5141\u8bb8<\/strong>\u201d\uff0c\u540e\u9762\u53ef\u80fd\u5c31\u4e0d\u77e5\u9053\u8981\u53bb\u54ea\u91cc\u518d\u5f00\u542f\u8fd9\u4e2a\u6743\u9650\u4e86\u3002\u8fd9\u5c31\u8981\u6c42\u6211\u4eec\u5e94\u7528\u5728\u6bcf\u6b21\u8c03\u7528\u76f8\u5173\u529f\u80fd\u7684\u65f6\u5019\u5148\u83b7\u53d6\u76f8\u5173\u7684\u6388\u6743\u72b6\u6001\uff0c\u5982\u679c\u8fd8\u6ca1\u6388\u6743\u5219\u5f39\u51fa\u6388\u6743\u7533\u8bf7\u7684\u63d0\u793a\u6846\u3002\u5982\u679c\u4e4b\u524d\u88ab\u62d2\u7edd\u4e86\uff0c\u5219\u5f39\u51fa\u76f8\u5173\u63d0\u793a\u6846\u8ba9\u7528\u6237\u5f88\u65b9\u4fbf\u5730\u81ea\u52a8\u8df3\u8f6c\u5230\u8bbe\u7f6e\u9875\u9762\u53bb\u4fee\u6539\u6743\u9650\u3002<br><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">1\uff0c\u6837\u4f8b\u6548\u679c\u56fe<\/h5>\n\n\n\n<p>\uff081\uff09\u8fd9\u91cc\u4ee5\u7167\u7247\u7684\u8bbf\u95ee\u6743\u9650\u4e3a\u4f8b\u3002\u4e3a\u65b9\u4fbf\u6f14\u793a\uff0c\u6211\u5728\u9875\u9762\u521d\u59cb\u5316\u5b8c\u6bd5\u540e\u5c31\u8bf7\u6c42\u6743\u9650\u3002<\/p>\n\n\n\n<p>\uff082\uff09\u7b2c\u4e00\u6b21\u8bf7\u6c42\u7684\u65f6\u5019\u6211\u4eec\u9009\u62e9\u201c<strong>\u4e0d\u5141\u8bb8<\/strong>\u201d\u3002\u518d\u6b21\u542f\u52a8\u7a0b\u5e8f\u65f6\uff0c\u4f1a\u63d0\u793a\u7528\u6237\u7167\u7247\u8bbf\u95ee\u53d7\u9650\uff0c\u9700\u8981\u6388\u6743\u3002<\/p>\n\n\n\n<p>\uff083\uff09\u70b9\u51fb\u201c\u8bbe\u7f6e\u201d\u6309\u94ae\u540e\u4fbf\u81ea\u52a8\u8df3\u8f6c\u5230\u7cfb\u7edf\u8bbe\u7f6e\u9875\u9762\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\/2021\/07\/image-72-1024x569.png\" alt=\"\" class=\"wp-image-3503\" width=\"519\" height=\"288\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-1024x569.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-300x167.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-768x427.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-830x461.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-230x128.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-350x194.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72-480x267.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-72.png 1278w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/figure><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">2\uff0c\u6837\u4f8b\u4ee3\u7801<\/h5>\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 Photos\n \nclass ViewController: UIViewController {\n     \n    override func viewDidLoad() {\n        _ = authorize()\n    }\n     \n    func authorize()->Bool{\n        let status = PHPhotoLibrary.authorizationStatus()\n         \n        switch status {\n        case .authorized:\n            return true\n             \n        case .notDetermined:\n            \/\/ \u8bf7\u6c42\u6388\u6743\n            PHPhotoLibrary.requestAuthorization({ (status) -> Void in\n                DispatchQueue.main.async(execute: { () -> Void in\n                    _ = self.authorize()\n                })\n            })\n             \n        default: ()\n        DispatchQueue.main.async(execute: { () -> Void in\n            let alertController = UIAlertController(title: \"\u7167\u7247\u8bbf\u95ee\u53d7\u9650\",\n                                                    message: \"\u70b9\u51fb\u201c\u8bbe\u7f6e\u201d\uff0c\u5141\u8bb8\u8bbf\u95ee\u60a8\u7684\u7167\u7247\",\n                                                    preferredStyle: .alert)\n             \n            let cancelAction = UIAlertAction(title:\"\u53d6\u6d88\", style: .cancel, handler:nil)\n             \n            let settingsAction = UIAlertAction(title:\"\u8bbe\u7f6e\", style: .default, handler: {\n                (action) -> Void in\n                let url = URL(string: UIApplicationOpenSettingsURLString)\n                if let url = url, UIApplication.shared.canOpenURL(url) {\n                    if #available(iOS 10, *) {\n                        UIApplication.shared.open(url, options: [:],\n                                                  completionHandler: {\n                                                    (success) in\n                        })\n                    } else {\n                       UIApplication.shared.openURL(url)\n                    }\n                }\n            })\n             \n            alertController.addAction(cancelAction)\n            alertController.addAction(settingsAction)\n             \n            self.present(alertController, animated: true, completion: nil)\n        })\n        }\n        return false\n    }\n  \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u9644\uff1a\u9ea6\u514b\u98ce\u6743\u9650\u7533\u8bf7<\/h5>\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\/07\/image-73.png\" alt=\"\" class=\"wp-image-3505\" width=\"378\" height=\"349\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-73.png 754w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-73-300x277.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-73-230x212.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-73-350x323.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/07\/image-73-480x443.png 480w\" sizes=\"(max-width: 378px) 100vw, 378px\" \/><\/figure><\/div>\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 Photos\n \nclass ViewController: UIViewController {\n     \n    override func viewDidLoad() {\n        _ = authorize()\n    }\n     \n    func authorize()->Bool{\n        let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeAudio)\n         \n        switch status {\n        case .authorized:\n            return true\n             \n        case .notDetermined:\n            \/\/ \u8bf7\u6c42\u6388\u6743\n            AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: {\n                (status) in\n                DispatchQueue.main.async(execute: { () -> Void in\n                    _ = self.authorize()\n                })\n            })           \n        default: ()\n        DispatchQueue.main.async(execute: { () -> Void in\n            let alertController = UIAlertController(title: \"\u9ea6\u514b\u98ce\u8bbf\u95ee\u53d7\u9650\",\n                                                    message: \"\u70b9\u51fb\u201c\u8bbe\u7f6e\u201d\uff0c\u5141\u8bb8\u8bbf\u95ee\u60a8\u7684\u9ea6\u514b\u98ce\",\n                                                    preferredStyle: .alert)\n             \n            let cancelAction = UIAlertAction(title:\"\u53d6\u6d88\", style: .cancel, handler:nil)\n             \n            let settingsAction = UIAlertAction(title:\"\u8bbe\u7f6e\", style: .default, handler: {\n                (action) -> Void in\n                let url = URL(string: UIApplicationOpenSettingsURLString)\n                if let url = url, UIApplication.shared.canOpenURL(url) {\n                    if #available(iOS 10, *) {\n                        UIApplication.shared.open(url, options: [:],\n                                                  completionHandler: {\n                                                    (success) in\n                        })\n                    } else {\n                        UIApplication.shared.openURL(url)\n                    }\n                }\n            })\n             \n            alertController.addAction(cancelAction)\n            alertController.addAction(settingsAction)\n             \n            self.present(alertController, animated: true, completion: nil)\n        })\n        }\n        return false\n    }\n     \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8e&nbsp;iOS&nbsp;\u7cfb\u7edf\u7684\u5b89\u5168\u9650\u5236\uff0cApp&nbsp;\u5982\u679c\u9700\u8981\u8bbf\u95ee\u8bbe\u5907\u7684\u901a\u8baf\u5f55\u3001\u9ea6\u514b\u98ce\u3001 \u76f8\u518c\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3501"}],"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=3501"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3501\/revisions"}],"predecessor-version":[{"id":3506,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/3501\/revisions\/3506"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}