{"id":6698,"date":"2025-06-01T12:00:35","date_gmt":"2025-06-05T04:56:34","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6698"},"modified":"2025-06-05T12:00:35","modified_gmt":"2025-06-05T04:56:34","slug":"https-badgameshow-com-steven-27","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-27\/","title":{"rendered":"Swift 2025\uff1a\u5982\u4f55\u5c07\u7167\u7247\u5b58\u5132\u5230\u76f8\u518a\u4e2d \ud83d\udcf7\ud83d\udcda"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u5b58\u5132\u7167\u7247, iOS, UIImageWriteToSavedPhotosAlbum\"><\/p>\n<h1>Swift 2025\uff1a\u5982\u4f55\u5c07\u7167\u7247\u5b58\u5132\u5230\u76f8\u518a\u4e2d \ud83d\udcf7\ud83d\udcda<\/h1>\n<p>\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 Swift \u5c07\u7167\u7247\u5b58\u5132\u5230 iOS \u76f8\u518a\u4e2d\u3002Swift \u662f\u4e00\u7a2e\u5feb\u901f\u3001\u5b89\u5168\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5ee3\u6cdb\u7528\u65bc\u958b\u767c iOS\u3001macOS\u3001watchOS \u548c tvOS \u61c9\u7528\u7a0b\u5f0f\u3002\u96a8\u8457 Swift \u8a9e\u8a00\u7684\u767c\u5c55\uff0c\u672c\u6587\u5c07\u66f4\u65b0\u70ba 2025 \u5e74\u7684\u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff0c\u8b93\u4f60\u80fd\u5920\u8f15\u9b06\u5be6\u73fe\u9019\u500b\u529f\u80fd\u3002<\/p>\n<h2>\u70ba\u4ec0\u9ebc\u8981\u5b58\u5132\u7167\u7247\u5230\u76f8\u518a\uff1f<\/h2>\n<p>\u5c07\u7167\u7247\u5b58\u5132\u5230\u76f8\u518a\u80fd\u5920\u8b93\u4f60\u7684\u7167\u7247\u66f4\u5bb9\u6613\u88ab\u5176\u4ed6\u61c9\u7528\u7a0b\u5f0f\u8a2a\u554f\uff0c\u4fbf\u65bc\u5206\u4eab\u548c\u7ba1\u7406\u3002\u6b64\u5916\uff0c\u9019\u6a23\u7684\u64cd\u4f5c\u4e5f\u80fd\u8b93\u4f60\u7684\u7167\u7247\u66f4\u5bb9\u6613\u88ab\u641c\u5c0b\u5f15\u64ce\u6536\u9304\uff0c\u63d0\u5347\u5176\u80fd\u898b\u5ea6\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 Swift \u5c07\u7167\u7247\u5b58\u5132\u5230\u76f8\u518a\uff1f<\/h2>\n<p>\u8981\u4f7f\u7528 Swift \u5c07\u7167\u7247\u5b58\u5132\u5230\u76f8\u518a\uff0c\u4f60\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u5f15\u5165\u5fc5\u8981\u7684\u6846\u67b6\u3002<\/li>\n<li>\u8acb\u6c42\u76f8\u7c3f\u5b58\u53d6\u6b0a\u9650\u3002<\/li>\n<li>\u5c07\u7167\u7247\u8f49\u63db\u70ba <strong>UIImage<\/strong> \u5c0d\u8c61\u3002<\/li>\n<li>\u4f7f\u7528 <strong>PHPhotoLibrary<\/strong> \u5c07\u7167\u7247\u5beb\u5165\u76f8\u518a\u3002<\/li>\n<\/ol>\n<h3>\u6b65\u9a5f 1: \u5f15\u5165\u5fc5\u8981\u7684\u6846\u67b6<\/h3>\n<p>\u5728\u4f60\u7684 Swift \u6a94\u6848\u4e2d\u5f15\u5165 <strong>Photos<\/strong> \u6846\u67b6\uff1a<\/p>\n<pre><code>import Photos<\/code><\/pre>\n<h3>\u6b65\u9a5f 2: \u8acb\u6c42\u76f8\u7c3f\u5b58\u53d6\u6b0a\u9650<\/h3>\n<p>\u5728\u5beb\u5165\u76f8\u518a\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u8acb\u6c42\u4f7f\u7528\u8005\u7684\u8a31\u53ef\uff1a<\/p>\n<pre><code>PHPhotoLibrary.requestAuthorization { status in\n    if status == .authorized {\n        \/\/ \u53ef\u4ee5\u5b58\u53d6\u76f8\u518a\n    } else {\n        \/\/ \u62d2\u7d55\u5b58\u53d6\n    }\n}<\/code><\/pre>\n<h3>\u6b65\u9a5f 3: \u5c07\u5716\u7247\u8f49\u63db\u70ba UIImage \u5c0d\u8c61<\/h3>\n<p>\u63a5\u8457\uff0c\u4f60\u9700\u8981\u5c07\u5716\u7247\u8f49\u63db\u70ba <strong>UIImage<\/strong> \u5c0d\u8c61\uff1a<\/p>\n<pre><code>let image = UIImage(named: \"myImage.png\")<\/code><\/pre>\n<h3>\u6b65\u9a5f 4: \u4f7f\u7528 PHPhotoLibrary \u5c07\u7167\u7247\u5beb\u5165\u76f8\u518a<\/h3>\n<p>\u6700\u5f8c\uff0c\u5c07\u5716\u7247\u5b58\u5165\u76f8\u518a\uff1a<\/p>\n<pre><code>PHPhotoLibrary.shared().performChanges({\n    PHAssetChangeRequest.creationRequestForAsset(from: image!)\n}) { success, error in\n    if success {\n        print(\"\u7167\u7247\u5df2\u6210\u529f\u5b58\u5165\u76f8\u518a\")\n    } else if let error = error {\n        print(\"\u5b58\u5132\u5931\u6557\uff1a\\(error.localizedDescription)\")\n    }\n}<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<ul>\n<li>\u78ba\u4fdd\u4f60\u7684 app \u5df2\u7d93\u7372\u5f97\u76f8\u518a\u5b58\u53d6\u6b0a\u9650\u3002<\/li>\n<li>\u6aa2\u67e5\u5716\u7247\u662f\u5426\u6210\u529f\u8f49\u63db\u70ba <strong>UIImage<\/strong>\u3002<\/li>\n<li>\u5728\u6a21\u64ec\u5668\u4e2d\u6e2c\u8a66\u6642\uff0c\u7121\u6cd5\u5b58\u5132\u5716\u7247\u5230\u76f8\u518a\uff0c\u5efa\u8b70\u5728\u771f\u5be6\u8a2d\u5099\u4e0a\u6e2c\u8a66\u3002<\/li>\n<\/ul>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 Swift \u5c07\u7167\u7247\u5b58\u5132\u5230\u76f8\u518a\u4e2d\uff0c\u6db5\u84cb\u4e86\u5fc5\u8981\u7684\u6b65\u9a5f\u8207\u6700\u4f73\u5be6\u8e10\u3002\u5e0c\u671b\u9019\u4e9b\u77e5\u8b58\u80fd\u5920\u5e6b\u52a9\u4f60\u5728\u958b\u767c iOS \u61c9\u7528\u7a0b\u5f0f\u6642\u66f4\u6709\u6548\u5730\u8655\u7406\u7167\u7247\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: \u70ba\u4ec0\u9ebc\u6211\u7121\u6cd5\u5b58\u5132\u7167\u7247\u5230\u76f8\u518a\uff1f<\/h3>\n<p>A1: \u78ba\u4fdd\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u5df2\u7372\u5f97\u76f8\u518a\u7684\u5b58\u53d6\u6b0a\u9650\uff0c\u4e26\u6aa2\u67e5\u5716\u7247\u662f\u5426\u6b63\u78ba\u8f49\u63db\u70ba <strong>UIImage<\/strong> \u5c0d\u8c61\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u67e5\u770b\u5b58\u5132\u7684\u7167\u7247\uff1f<\/h3>\n<p>A2: \u4f60\u53ef\u4ee5\u5728 iOS \u7684\u300c\u7167\u7247\u300d\u61c9\u7528\u7a0b\u5f0f\u4e2d\u67e5\u770b\u5df2\u5b58\u5132\u7684\u7167\u7247\u3002<\/p>\n<h3>Q3: \u9084\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5b58\u5132\u7167\u7247\u55ce\uff1f<\/h3>\n<p>A3: \u9664\u4e86\u4f7f\u7528 <strong>UIImageWriteToSavedPhotosAlbum<\/strong> \u65b9\u6cd5\u5916\uff0c\u4f7f\u7528 <strong>PHPhotoLibrary<\/strong> \u4e5f\u662f\u4e00\u500b\u73fe\u4ee3\u5316\u7684\u65b9\u6cd5\uff0c\u63d0\u4f9b\u66f4\u591a\u7684\u63a7\u5236\u548c\u529f\u80fd\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5b58\u5132\u7167\u7247\u5230\u76f8\u518a-\ud83d\udcf7\ud83d\udcda_1675394098.7749279.webp\" alt=\"Swift \u5b58\u5132\u7167\u7247\u5230\u76f8\u518a \ud83d\udcf7\ud83d\udcda\" title=\"Swift \u5b58\u5132\u7167\u7247, UIImageWriteToSavedPhotosAlbum, PHPhotoLibrary, \u7167\u7247\u5b58\u5165\u76f8\u518a, Swift \u76f8\u518a\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u5c07\u7167\u7247\u5b58\u5165\u76f8\u518a\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528UIImageWriteToSavedPhotosAlbum\u51fd\u6578\u5c07\u7167\u7247\u5b58\u5165\u76f8\u518a\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528PHPhotoLibrary\u5c07\u7167\u7247\u5b58\u5165\u76f8\u518a\u3002<\/p>\n","protected":false},"author":1,"featured_media":6696,"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-6698","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-\u5b58\u5132\u7167\u7247\u5230\u76f8\u518a-\ud83d\udcf7\ud83d\udcda_1675394098.7749279.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1K2","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6698","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=6698"}],"version-history":[{"count":0,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6698\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6696"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}