{"id":6859,"date":"2025-05-29T13:30:43","date_gmt":"2025-06-05T06:03:43","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6859"},"modified":"2025-06-05T13:30:43","modified_gmt":"2025-06-05T06:03:43","slug":"https-badgameshow-com-steven-105","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-105\/","title":{"rendered":"Swift UIImagePickerController \u4f7f\u7528\u6307\u5357\ud83d\udcf7 &#8211; 2025 \u6700\u65b0\u7167\u7247\u5eab\u9078\u64c7\u6559\u5b78"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UIImagePickerController, \u7167\u7247\u5eab\u9078\u64c7\u6559\u5b78, iOS, app\u958b\u767c, 2025\"><\/p>\n<h1>Swift UIImagePickerController \u4f7f\u7528\u6307\u5357\ud83d\udcf7 &#8211; 2025 \u6700\u65b0\u7167\u7247\u5eab\u9078\u64c7\u6559\u5b78<\/h1>\n<p>\u5728 Swift \u4e2d\uff0c<strong>UIImagePickerController<\/strong> \u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u985e\u5225\uff0c\u8b93\u4f7f\u7528\u8005\u80fd\u5920\u5f9e\u7167\u7247\u5eab\u4e2d\u9078\u64c7\u7167\u7247\uff0c\u4e26\u5c07\u5176\u8f09\u5165 App \u4e2d\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 UIImagePickerController \u4f86\u9078\u64c7\u7167\u7247\uff0c\u4e26\u63d0\u4f9b\u5be6\u4f5c\u7bc4\u4f8b\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u4ee5\u78ba\u4fdd\u60a8\u7684\u61c9\u7528\u7a0b\u5f0f\u5728 2025 \u5e74\u4f9d\u7136\u7b26\u5408\u6700\u65b0\u7684\u6a19\u6e96\u3002<\/p>\n<h2>\u524d\u7f6e\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u5728 <strong>info.plist<\/strong> \u4e2d\u52a0\u5165 <strong>Privacy &#8211; Photo Library Usage Description<\/strong>\uff0c\u9019\u662f\u70ba\u4e86\u63d0\u4f9b\u4f7f\u7528\u8005\u4f7f\u7528\u7167\u7247\u5eab\u7684\u6b0a\u9650\u3002\u52d9\u5fc5\u63d0\u4f9b\u6e05\u695a\u7684\u63cf\u8ff0\uff0c\u4ee5\u589e\u5f37\u4f7f\u7528\u8005\u7684\u4fe1\u4efb\u611f\u3002<\/p>\n<h2>\u4f7f\u7528 UIImagePickerController<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5efa\u7acb\u4e00\u500b <strong>UIImagePickerController<\/strong> \u7684\u5be6\u4f8b\uff0c\u4e26\u5c07 <strong>sourceType<\/strong> \u8a2d\u5b9a\u70ba <strong>.photoLibrary<\/strong>\uff0c\u4ee5\u6307\u5b9a\u5f9e\u7167\u7247\u5eab\u9078\u64c7\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let imagePickerController = UIImagePickerController()\nimagePickerController.sourceType = .photoLibrary\n<\/code><\/pre>\n<p>\u63a5\u8457\uff0c\u60a8\u9700\u8981\u8a2d\u5b9a <strong>delegate<\/strong>\uff0c\u4ee5\u6307\u5b9a\u7576\u4f7f\u7528\u8005\u9078\u64c7\u5b8c\u7167\u7247\u5f8c\uff0c\u6703\u547c\u53eb\u54ea\u500b\u7269\u4ef6\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">imagePickerController.delegate = self\n<\/code><\/pre>\n<p>\u6700\u5f8c\uff0c\u5c07 <strong>UIImagePickerController<\/strong> \u986f\u793a\u51fa\u4f86\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">present(imagePickerController, animated: true, completion: nil)\n<\/code><\/pre>\n<h2>\u53d6\u5f97\u9078\u64c7\u7684\u7167\u7247<\/h2>\n<p>\u7576\u4f7f\u7528\u8005\u9078\u64c7\u5b8c\u7167\u7247\u5f8c\uff0c\u6703\u547c\u53eb <strong>UIImagePickerControllerDelegate<\/strong> \u7684 <strong>didFinishPickingMediaWithInfo<\/strong> \u65b9\u6cd5\u3002\u5728\u6b64\u65b9\u6cd5\u4e2d\uff0c\u60a8\u53ef\u4ee5\u53d6\u5f97\u4f7f\u7528\u8005\u9078\u64c7\u7684\u7167\u7247\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {\n    if let image = info[.originalImage] as? UIImage {\n        \/\/ \u53d6\u5f97\u4f7f\u7528\u8005\u9078\u64c7\u7684\u7167\u7247\u4e26\u9032\u884c\u76f8\u61c9\u8655\u7406\n    }\n    picker.dismiss(animated: true, completion: nil) \/\/ \u95dc\u9589\u9078\u64c7\u5668\n}\n<\/code><\/pre>\n<p>\u78ba\u4fdd\u5728\u9078\u64c7\u5b8c\u7167\u7247\u5f8c\uff0c\u60a8\u95dc\u9589\u9078\u64c7\u5668\uff0c\u4ee5\u63d0\u5347\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 <strong>UIImagePickerController<\/strong> \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u554f\u984c\uff0c\u4f8b\u5982\u672a\u7372\u5f97\u7167\u7247\u5eab\u7684\u5b58\u53d6\u6b0a\u9650\u3002\u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u60a8\u53ef\u4ee5\u5728 <strong>didFinishPickingMediaWithInfo<\/strong> \u65b9\u6cd5\u4e2d\u8655\u7406\u932f\u8aa4\uff0c\u4e26\u63d0\u4f9b\u4f7f\u7528\u8005\u9069\u7576\u7684\u63d0\u793a\u4fe1\u606f\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u5f9e\u7167\u7247\u5eab\u9078\u64c7\u7167\u7247\u5916\uff0c<strong>UIImagePickerController<\/strong> \u9084\u53ef\u4ee5\u7528\u4f86\u62cd\u651d\u7167\u7247\u3002\u60a8\u53ea\u9700\u5c07 <strong>sourceType<\/strong> \u8a2d\u5b9a\u70ba <strong>.camera<\/strong> \u5373\u53ef\u3002\u9019\u70ba\u60a8\u7684\u61c9\u7528\u958b\u767c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u9748\u6d3b\u6027\u548c\u529f\u80fd\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 <strong>UIImagePickerController<\/strong> \u4f86\u8b93\u4f7f\u7528\u8005\u5f9e\u7167\u7247\u5eab\u4e2d\u9078\u64c7\u7167\u7247\uff0c\u4e26\u5c07\u7167\u7247\u8f09\u5165 App \u4e2d\u3002\u9019\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u63d0\u5347\u60a8\u7684\u61c9\u7528\u7a0b\u5f0f\u7684\u4f7f\u7528\u8005\u4e92\u52d5\u6027\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<ul>\n<li><strong>Q1:<\/strong> \u5982\u4f55\u8655\u7406\u672a\u6388\u6b0a\u7684\u7167\u7247\u5eab\u8a2a\u554f\uff1f<br \/><strong>A:<\/strong> \u60a8\u53ef\u5728 info.plist \u4e2d\u6dfb\u52a0\u63cf\u8ff0\uff0c\u4e26\u6aa2\u67e5\u6388\u6b0a\u72c0\u614b\u4f86\u63d0\u793a\u7528\u6236\u3002<\/li>\n<li><strong>Q2:<\/strong> UIImagePickerController \u53ef\u4ee5\u7528\u65bc\u62cd\u7167\u55ce\uff1f<br \/><strong>A:<\/strong> \u662f\u7684\uff0c\u60a8\u53ea\u9700\u5c07 sourceType \u8a2d\u5b9a\u70ba .camera\u3002<\/li>\n<li><strong>Q3:<\/strong> \u5982\u4f55\u81ea\u5b9a\u7fa9 UIImagePickerController \u7684\u5916\u89c0\uff1f<br \/><strong>A:<\/strong> \u60a8\u53ef\u4ee5\u4f7f\u7528 UINavigationController \u4f86\u5305\u88dd UIImagePickerController\uff0c\u4e26\u81ea\u5b9a\u7fa9\u5c0e\u822a\u6b04\u7684\u5916\u89c0\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIImagePickerController\u4f7f\u7528\ud83d\udcf7-\u7167\u7247\u5eab\u9078\u64c7\u6559\u5b78_1675397136.698557.webp\" alt=\"Swift UIImagePickerController\u4f7f\u7528\ud83d\udcf7 - \u7167\u7247\u5eab\u9078\u64c7\u6559\u5b78\" title=\"Swift UIImagePickerController, \u7167\u7247\u5eab\u9078\u64c7, methods()\u51fd\u6578, \u7167\u7247\u5eab, \u7167\u7247\u9078\u64c7\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981(Description):\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528SwiftUIImagePickerController\u4f86\u9078\u64c7\u7167\u7247\u5eab\u4e2d\u7684\u7167\u7247\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528SwiftUIImagePickerController\u4f86\u9078\u64c7\u7167\u7247\u5eab\u4e2d\u7684\u7167\u7247\uff0c\u4e26\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528methods()\u51fd\u6578\u4f86\u5b8c\u6210\u7167\u7247\u5eab\u9078\u64c7\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":6857,"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-6859","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-UIImagePickerController\u4f7f\u7528\ud83d\udcf7-\u7167\u7247\u5eab\u9078\u64c7\u6559\u5b78_1675397136.698557.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1MD","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6859","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=6859"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6859\/revisions"}],"predecessor-version":[{"id":13511,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6859\/revisions\/13511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6857"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}