{"id":6874,"date":"2025-06-03T13:54:56","date_gmt":"2025-06-05T06:09:56","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6874"},"modified":"2025-06-05T13:54:56","modified_gmt":"2025-06-05T06:09:56","slug":"https-badgameshow-com-steven-113","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-113\/","title":{"rendered":"Swift \u62cd\u7167\u529f\u80fd\u5be6\u4f5c\uff1a2025 \u6700\u65b0 UIImagePickerController \u6559\u5b78 \ud83d\udcf7"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UIImagePickerController, \u62cd\u7167, iOS \u958b\u767c, \u7167\u7247\u9078\u64c7, 2025\"><\/p>\n<h1>Swift \u62cd\u7167\u529f\u80fd\u5be6\u4f5c\uff1a2025 \u6700\u65b0 UIImagePickerController \u6559\u5b78 \ud83d\udcf7<\/h1>\n<p>\u5728\u73fe\u4eca\u7684 iOS \u61c9\u7528\u7a0b\u5f0f\u958b\u767c\u4e2d\uff0c\u62cd\u7167\u529f\u80fd\u662f\u8a31\u591a\u61c9\u7528\u7a0b\u5f0f\u7684\u91cd\u8981\u7d44\u6210\u90e8\u5206\u3002\u4f7f\u7528 Swift \u8a9e\u8a00\uff0c\u6211\u5011\u53ef\u4ee5\u900f\u904e <strong>UIImagePickerController<\/strong> \u4f86\u8f15\u9b06\u6574\u5408\u62cd\u7167\u8207\u7167\u7247\u9078\u64c7\u7684\u529f\u80fd\u3002\u672c\u6587\u5c07\u63d0\u4f9b 2025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u6709\u6548\u5be6\u4f5c\u62cd\u7167\u529f\u80fd\u3002<\/p>\n<h2>UIImagePickerController \u7c21\u4ecb<\/h2>\n<p><strong>UIImagePickerController<\/strong> \u662f iOS \u5167\u5efa\u7684\u4e00\u500b\u63a7\u5236\u5668\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5f9e\u76f8\u7c3f\u6216\u76f8\u6a5f\u4e2d\u53d6\u5f97\u7167\u7247\uff0c\u4e26\u652f\u63f4\u7de8\u8f2f\u529f\u80fd\u3002\u901a\u904e\u6b63\u78ba\u7684\u8a2d\u5b9a\u8207\u4f7f\u7528\uff0c\u958b\u767c\u8005\u80fd\u5920\u63d0\u4f9b\u6d41\u66a2\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>\u4f7f\u7528 UIImagePickerController \u7684\u6e96\u5099\u5de5\u4f5c<\/h2>\n<p>\u5728\u4f7f\u7528 <strong>UIImagePickerController<\/strong> \u524d\uff0c\u9700\u5728 <strong>info.plist<\/strong> \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5169\u500b\u9375\u503c\uff0c\u4ee5\u4fbf\u7372\u5f97\u4f7f\u7528\u8005\u7684\u540c\u610f\uff1a<\/p>\n<ul>\n<li><strong>Privacy &#8211; Photo Library Usage Description<\/strong><\/li>\n<li><strong>Privacy &#8211; Camera Usage Description<\/strong><\/li>\n<\/ul>\n<h2>\u5be6\u4f5c UIImagePickerController<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 <strong>UIImagePickerController<\/strong> \u7684\u57fa\u672c\u7a0b\u5f0f\u78bc\uff0c\u5f9e\u76f8\u7c3f\u9078\u53d6\u7167\u7247\u4e26\u652f\u63f4\u7de8\u8f2f\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let imagePicker = UIImagePickerController()\nimagePicker.sourceType = .photoLibrary \/\/ \u53ef\u4ee5\u6539\u70ba .camera \u4f86\u4f7f\u7528\u76f8\u6a5f\nimagePicker.allowsEditing = true \/\/ \u8a2d\u5b9a\u662f\u5426\u5141\u8a31\u7de8\u8f2f\nimagePicker.delegate = self \/\/ \u8a2d\u5b9a delegate<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u986f\u793a\u5716\u7247\u9078\u64c7\u5668\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">present(imagePicker, animated: true, completion: nil)<\/code><\/pre>\n<h2>\u8655\u7406\u9078\u64c7\u7684\u7167\u7247<\/h2>\n<p>\u7576\u4f7f\u7528\u8005\u9078\u64c7\u5b8c\u7167\u7247\u5f8c\uff0c\u6703\u89f8\u767c delegate \u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u8655\u7406\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[.editedImage] as? UIImage {\n        \/\/ \u4f7f\u7528\u7de8\u8f2f\u5f8c\u7684\u7167\u7247\n    } else if let image = info[.originalImage] as? UIImage {\n        \/\/ \u4f7f\u7528\u539f\u59cb\u7167\u7247\n    }\n    dismiss(animated: true, completion: nil) \/\/ \u95dc\u9589\u5716\u7247\u9078\u64c7\u5668\n}<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 <strong>UIImagePickerController<\/strong> \u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\uff1a<\/p>\n<ul>\n<li><strong>\u672a\u7372\u5f97\u76f8\u6a5f\u6216\u76f8\u7c3f\u6b0a\u9650\uff1a<\/strong> \u78ba\u4fdd\u5728 <strong>info.plist<\/strong> \u4e2d\u6b63\u78ba\u8a2d\u7f6e\u4f7f\u7528\u8aaa\u660e\u3002<\/li>\n<li><strong>delegate \u672a\u6b63\u78ba\u8a2d\u7f6e\uff1a<\/strong> \u78ba\u4fdd delegate \u5df2\u8a2d\u70ba\u7576\u524d\u63a7\u5236\u5668\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u62cd\u7167\u529f\u80fd\uff0c\u958b\u767c\u8005\u9084\u53ef\u4ee5\u8003\u616e\u4ee5\u4e0b\u5ef6\u4f38\u61c9\u7528\uff1a<\/p>\n<ul>\n<li>\u5c07\u62cd\u651d\u7684\u7167\u7247\u4e0a\u50b3\u81f3\u4f3a\u670d\u5668\u3002<\/li>\n<li>\u63d0\u4f9b\u7167\u7247\u7de8\u8f2f\u529f\u80fd\uff0c\u5982\u88c1\u526a\u3001\u6ffe\u93e1\u7b49\u3002<\/li>\n<li>\u5c07\u9078\u53d6\u7684\u7167\u7247\u8207\u793e\u4ea4\u5a92\u9ad4\u5206\u4eab\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u62cd\u7167\uff1aUIImagePickerController-\ud83d\udcf7_1675397487.8302422.webp\" alt=\"Swift \u62cd\u7167\uff1aUIImagePickerController \ud83d\udcf7\" title=\"Swift\u62cd\u7167, UIImagePickerController, \u62cd\u7167\u7a0b\u5f0f\u78bc, \u62cd\u7167\u529f\u80fd, \u62cd\u7167\u6280\u8853\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: \u5982\u4f55\u8b93\u4f7f\u7528\u8005\u5f9e\u76f8\u6a5f\u62cd\u7167\u800c\u4e0d\u662f\u5f9e\u76f8\u7c3f\u9078\u64c7\uff1f<\/h3>\n<p>A1: \u5728\u8a2d\u7f6e <strong>imagePicker.sourceType<\/strong> \u6642\uff0c\u5c07\u5176\u8a2d\u70ba <strong>.camera<\/strong> \u5373\u53ef\u3002<\/p>\n<h3>Q2: \u5982\u679c\u4f7f\u7528\u8005\u62d2\u7d55\u76f8\u6a5f\u6216\u76f8\u7c3f\u7684\u6b0a\u9650\uff0c\u8a72\u600e\u9ebc\u8fa6\uff1f<\/h3>\n<p>A2: \u53ef\u4ee5\u5728\u61c9\u7528\u7a0b\u5f0f\u4e2d\u8655\u7406\u6b0a\u9650\u7684\u62d2\u7d55\u60c5\u6cc1\uff0c\u4e26\u5f15\u5c0e\u4f7f\u7528\u8005\u81f3\u8a2d\u5b9a\u958b\u555f\u76f8\u6a5f\u6216\u76f8\u7c3f\u6b0a\u9650\u3002<\/p>\n<h3>Q3: \u5982\u4f55\u5728\u9078\u64c7\u7167\u7247\u5f8c\u9032\u884c\u7de8\u8f2f\uff1f<\/h3>\n<p>A3: \u4f7f\u7528\u8005\u9078\u64c7\u7167\u7247\u5f8c\uff0c\u53ef\u4ee5\u5728 <strong>imagePickerController(_:didFinishPickingMediaWithInfo:)<\/strong> \u65b9\u6cd5\u4e2d\u8655\u7406\u7de8\u8f2f\u5f8c\u7684\u7167\u7247\uff0c\u4e26\u5be6\u73fe\u81ea\u5b9a\u7fa9\u7684\u7de8\u8f2f\u529f\u80fd\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5728Swift\u4e2d\uff0c\u4f7f\u7528UIImagePickerController\u53ef\u4ee5\u5feb\u901f\u62cd\u7167\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528UIImagePickerController\u4f86\u62cd\u7167\uff0c\u4e26\u63d0\u4f9b\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n","protected":false},"author":1,"featured_media":6873,"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-6874","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-\u62cd\u7167\uff1aUIImagePickerController-\ud83d\udcf7_1675397487.8302422.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1MS","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6874","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=6874"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6874\/revisions"}],"predecessor-version":[{"id":13601,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6874\/revisions\/13601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6873"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}