{"id":6854,"date":"2025-06-02T14:20:05","date_gmt":"2025-06-05T06:37:04","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6854"},"modified":"2025-06-05T14:20:05","modified_gmt":"2025-06-05T06:37:04","slug":"https-badgameshow-com-steven-103","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-103\/","title":{"rendered":"Swift \u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\uff1a2025 \u5e74\u6700\u65b0\u6559\u5b78\u8207\u6700\u4f73\u5be6\u8e10 \ud83d\udcf7\ud83d\udd25"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668, Swift 2025, iOS \u958b\u767c, UIImagePickerController\"><\/p>\n<h1>Swift \u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\uff1a2025 \u5e74\u6700\u65b0\u6559\u5b78\u8207\u6700\u4f73\u5be6\u8e10 \ud83d\udcf7\ud83d\udd25<\/h1>\n<p>\u5728 iOS \u958b\u767c\u4e2d\uff0c\u8b93\u4f7f\u7528\u8005\u80fd\u5920\u5f9e\u76f8\u7c3f\u9078\u64c7\u5716\u7247\u6216\u5f9e\u76f8\u6a5f\u62cd\u651d\u7167\u7247\u662f\u5e38\u898b\u9700\u6c42\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\uff0c\u4e26\u63d0\u4f9b 2025 \u5e74\u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u8f15\u9b06\u5730\u5b8c\u6210\u9019\u9805\u529f\u80fd\u3002<\/p>\n<h2>\u5be6\u73fe\u6b65\u9a5f<\/h2>\n<p>\u8981\u5be6\u73fe\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\uff0c\u7b2c\u4e00\u6b65\u662f\u5fc5\u9808\u5728 <strong>info.plist<\/strong> \u4e2d\u52a0\u5165\u4ee5\u4e0b\u5169\u500b\u9375\u503c\uff0c\u4ee5\u4fbf\u7372\u53d6\u4f7f\u7528\u8005\u6388\u6b0a\uff1a<\/p>\n<p>&#8211; <strong>Privacy &#8211; Photo Library Usage Description<\/strong><br \/>\n&#8211; <strong>Privacy &#8211; Camera Usage Description<\/strong><\/p>\n<p>\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u61c9\u7528\u7a0b\u5f0f\u80fd\u5920\u53d6\u5f97\u5b58\u53d6\u76f8\u7c3f\u6216\u76f8\u6a5f\u7684\u6b0a\u9650\u3002<\/p>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5275\u5efa\u4e00\u500b <strong>UIImagePickerController<\/strong> \u7684\u5be6\u4f8b\uff0c\u4e26\u8a2d\u5b9a\u5176 <strong>sourceType<\/strong> \u5c6c\u6027\uff0c\u6c7a\u5b9a\u4f7f\u7528\u8005\u53ef\u4ee5\u5f9e\u54ea\u88e1\u9078\u64c7\u5716\u7247\u3002\u4ee5\u4e0b\u662f\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let imagePicker = UIImagePickerController()\nimagePicker.sourceType = .photoLibrary<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u8a2d\u5b9a <strong>imagePicker<\/strong> \u7684 <strong>delegate<\/strong> \u5c6c\u6027\uff0c\u4ee5\u4fbf\u5728\u4f7f\u7528\u8005\u9078\u64c7\u5b8c\u5716\u7247\u5f8c\u57f7\u884c\u76f8\u95dc\u52d5\u4f5c\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">imagePicker.delegate = self<\/code><\/pre>\n<p>\u6700\u5f8c\uff0c\u5c07 <strong>imagePicker<\/strong> \u986f\u793a\u5728\u756b\u9762\u4e0a\uff0c\u8b93\u4f7f\u7528\u8005\u958b\u59cb\u9078\u64c7\u5716\u7247\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">present(imagePicker, animated: true, completion: nil)<\/code><\/pre>\n<h2>\u81ea\u5b9a\u7fa9\u5916\u89c0<\/h2>\n<p>\u82e5\u60f3\u8981\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\u7684\u5916\u89c0\uff0c\u53ef\u4ee5\u4f7f\u7528 <strong>UINavigationController<\/strong> \u5305\u88dd <strong>UIImagePickerController<\/strong>\u3002\u4ee5\u4e0b\u70ba\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let navigationController = UINavigationController(rootViewController: imagePicker)\npresent(navigationController, animated: true, completion: nil)<\/code><\/pre>\n<p>\u63a5\u8457\uff0c\u53ef\u4ee5\u8a2d\u5b9a <strong>UINavigationController<\/strong> \u7684 <strong>navigationBar<\/strong> \u5c6c\u6027\uff0c\u6539\u8b8a\u5c0e\u89bd\u5217\u7684\u5916\u89c0\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">navigationController.navigationBar.barTintColor = .red\nnavigationController.navigationBar.tintColor = .white\nnavigationController.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u8b93\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\u7684\u5916\u89c0\u7b26\u5408\u61c9\u7528\u7a0b\u5f0f\u7684\u6574\u9ad4\u8a2d\u8a08\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>1. **\u6b0a\u9650\u672a\u7372\u5f97**\uff1a\u4f7f\u7528\u8005\u672a\u6388\u6b0a\u76f8\u7247\u5b58\u53d6\uff0c\u9700\u6aa2\u67e5 <strong>info.plist<\/strong> \u4e2d\u7684\u63cf\u8ff0\u662f\u5426\u6b63\u78ba\u3002<br \/>\n2. **delegate \u672a\u8a2d\u5b9a**\uff1a\u82e5\u672a\u8a2d\u5b9a <strong>imagePicker.delegate<\/strong>\uff0c\u5c07\u7121\u6cd5\u7372\u53d6\u9078\u64c7\u5716\u7247\u7684\u56de\u8abf\u3002<br \/>\n3. **UI \u4e0d\u986f\u793a**\uff1a\u78ba\u4fdd <strong>present<\/strong> \u65b9\u6cd5\u7684\u8abf\u7528\u5728\u4e3b\u7dda\u7a0b\u4e2d\uff0c\u5426\u5247 UI \u53ef\u80fd\u4e0d\u6703\u986f\u793a\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\u53ef\u4ee5\u64f4\u5c55\u61c9\u7528\u65bc\u4e0d\u540c\u7684\u5834\u666f\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8211; \u5728\u793e\u4ea4\u5a92\u9ad4\u61c9\u7528\u4e2d\uff0c\u8b93\u4f7f\u7528\u8005\u4e0a\u50b3\u5716\u7247\u3002<br \/>\n&#8211; \u5728\u7167\u7247\u7de8\u8f2f\u61c9\u7528\u4e2d\uff0c\u8b93\u4f7f\u7528\u8005\u9078\u64c7\u7de8\u8f2f\u7684\u5716\u7247\u3002<br \/>\n&#8211; \u5728\u96fb\u5b50\u5546\u52d9\u61c9\u7528\u4e2d\uff0c\u8b93\u4f7f\u7528\u8005\u4e0a\u50b3\u7522\u54c1\u5716\u7247\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\uff0c\u4e26\u63d0\u4f9b\u4e86 2025 \u5e74\u6700\u65b0\u7684\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\u3002\u4f7f\u7528 <strong>UIImagePickerController<\/strong> \u548c <strong>UINavigationController<\/strong> \u7684\u7d44\u5408\uff0c\u53ef\u4ee5\u8f15\u9b06\u5730\u8b93\u4f7f\u7528\u8005\u9078\u64c7\u5716\u7247\u4e26\u81ea\u5b9a\u7fa9\u5916\u89c0\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u5728\u5716\u7247\u9078\u64c7\u5668\u4e2d\u986f\u793a\u76f8\u6a5f\u9078\u9805\uff1f<\/h3>\n<p>\u5728\u8a2d\u5b9a <strong>sourceType<\/strong> \u6642\uff0c\u53ef\u4ee5\u5c07\u5176\u8a2d\u70ba <strong>.camera<\/strong>\uff0c\u4e26\u78ba\u4fdd\u5df2\u7372\u53d6\u76f8\u6a5f\u4f7f\u7528\u6b0a\u9650\u3002<\/p>\n<h3>2. \u5982\u679c\u5716\u7247\u9078\u64c7\u5668\u4e0d\u986f\u793a\uff0c\u8a72\u5982\u4f55\u8655\u7406\uff1f<\/h3>\n<p>\u6aa2\u67e5\u662f\u5426\u5728\u4e3b\u7dda\u7a0b\u4e2d\u547c\u53eb <strong>present<\/strong> \u65b9\u6cd5\uff0c\u4e26\u78ba\u4fdd <strong>delegate<\/strong> \u5df2\u6b63\u78ba\u8a2d\u5b9a\u3002<\/p>\n<h3>3. \u5982\u4f55\u8655\u7406\u4f7f\u7528\u8005\u62d2\u7d55\u76f8\u7c3f\u6216\u76f8\u6a5f\u6b0a\u9650\u7684\u60c5\u6cc1\uff1f<\/h3>\n<p>\u53ef\u4ee5\u5728\u61c9\u7528\u4e2d\u63d0\u4f9b\u63d0\u793a\uff0c\u6307\u5c0e\u4f7f\u7528\u8005\u5982\u4f55\u5728\u8a2d\u5b9a\u4e2d\u958b\u555f\u6b0a\u9650\uff0c\u4e26\u9069\u7576\u8655\u7406\u62d2\u7d55\u7684\u60c5\u6cc1\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668-\ud83d\udcf7\ud83d\udd25_1675397039.833672.webp\" alt=\"Swift \u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668 \ud83d\udcf7\ud83d\udd25\" title=\"Swift \u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\u3001Swift \u5716\u7247\u9078\u64c7\u5668\u3001Swift \u5716\u7247\u9078\u64c7\u3001Swift \u5716\u7247\u9078\u64c7\u529f\u80fd\u3001Swift \u5716\u7247\u9078\u64c7\u6280\u8853\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u638c\u63e1Swift\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668\u7684\u6280\u8853\u3002<\/p>\n","protected":false},"author":1,"featured_media":6853,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-6854","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u81ea\u5b9a\u7fa9\u5716\u7247\u9078\u64c7\u5668-\ud83d\udcf7\ud83d\udd25_1675397039.833672.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1My","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6854"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6854\/revisions"}],"predecessor-version":[{"id":13523,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6854\/revisions\/13523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6853"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}