{"id":6873,"date":"2025-10-01T15:00:28","date_gmt":"2025-10-01T07:00:28","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6873"},"modified":"2025-10-01T15:00:28","modified_gmt":"2025-10-01T07:00:28","slug":"cloudkit-%e9%87%8c%e8%ae%b0%e5%bd%95%e5%92%8c%e6%96%87%e4%bb%b6%e7%9a%84%e5%ad%98%e5%82%a8","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6873","title":{"rendered":"CloudKit \u91cc\u8bb0\u5f55\u548c\u6587\u4ef6\u7684\u5b58\u50a8"},"content":{"rendered":"<p>\u5728 CloudKit \u4e2d\uff0c<strong>\u8bb0\u5f55\uff08Records\uff09<\/strong> \u548c<strong>\u6587\u4ef6\uff08Files\/Assets\uff09<\/strong> \u662f\u4e24\u79cd\u4e0d\u540c\u7684\u6570\u636e\u5b58\u50a8\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5b83\u4eec\u7684\u5b58\u50a8\u673a\u5236\u3001\u4f7f\u7528\u573a\u666f\u548c\u9650\u5236\u90fd\u6709\u660e\u663e\u533a\u522b\uff1a<\/p>\n<h3>1. <strong>\u8bb0\u5f55\uff08Records\uff09<\/strong><\/h3>\n<h4>\u672c\u8d28<\/h4>\n<p>\u8bb0\u5f55\u662f CloudKit \u4e2d\u7ed3\u6784\u5316\u6570\u636e\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u7c7b\u4f3c\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\u7684&quot;\u884c&quot;\uff0c\u7531<strong>\u8bb0\u5f55\u7c7b\u578b\uff08Record Type\uff09<\/strong> \u5b9a\u4e49\u7ed3\u6784\uff08\u7c7b\u4f3c&quot;\u8868&quot;\uff09\uff0c\u5305\u542b\u591a\u4e2a<strong>\u5b57\u6bb5\uff08Fields\uff09<\/strong>\uff08\u7c7b\u4f3c&quot;\u5217&quot;\uff09\u3002<\/p>\n<h4>\u5b58\u50a8\u65b9\u5f0f<\/h4>\n<ul>\n<li><strong>\u7ed3\u6784\u5316\u5b58\u50a8<\/strong>\uff1a\u5b57\u6bb5\u503c\u7c7b\u578b\u53d7\u9650\uff0c\u652f\u6301\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u65e5\u671f\u3001\u5730\u7406\u4f4d\u7f6e\u3001\u5f15\u7528\uff08\u5173\u8054\u5176\u4ed6\u8bb0\u5f55\uff09\u7b49\u57fa\u7840\u7c7b\u578b\u3002<\/li>\n<li><strong>\u76f4\u63a5\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d<\/strong>\uff1a\u8bb0\u5f55\u672c\u8eab\uff08\u5305\u62ec\u6240\u6709\u5b57\u6bb5\uff09\u76f4\u63a5\u4fdd\u5b58\u5728 CloudKit \u6570\u636e\u5e93\uff08\u516c\u5171\/\u79c1\u6709\/\u5171\u4eab\u6570\u636e\u5e93\uff09\u4e2d\u3002<\/li>\n<li><strong>\u5927\u5c0f\u9650\u5236<\/strong>\uff1a\u5355\u6761\u8bb0\u5f55\u603b\u5927\u5c0f\u4e0d\u80fd\u8d85\u8fc7 <strong>1MB<\/strong>\uff0c\u9002\u5408\u5b58\u50a8\u5c0f\u578b\u6570\u636e\u3002<\/li>\n<\/ul>\n<h4>\u5178\u578b\u7528\u9014<\/h4>\n<ul>\n<li>\u7528\u6237\u4fe1\u606f\uff08\u7528\u6237\u540d\u3001\u504f\u597d\u8bbe\u7f6e\uff09<\/li>\n<li>\u6587\u672c\u5185\u5bb9\uff08\u7b14\u8bb0\u3001\u8bc4\u8bba\uff09<\/li>\n<li>\u7ed3\u6784\u5316\u5143\u6570\u636e\uff08\u6587\u7ae0\u6807\u9898\u3001\u53d1\u5e03\u65f6\u95f4\u3001\u70b9\u8d5e\u6570\uff09<\/li>\n<li>\u5173\u8054\u5173\u7cfb\uff08\u5982&quot;\u6587\u7ae0-\u4f5c\u8005&quot;\u7684\u5f15\u7528\u5173\u7cfb\uff09<\/li>\n<\/ul>\n<h4>\u64cd\u4f5c\u793a\u4f8b<\/h4>\n<pre><code class=\"language-swift\">\/\/ \u521b\u5efa\u4e00\u6761&quot;Article&quot;\u7c7b\u578b\u7684\u8bb0\u5f55\nlet articleRecord = CKRecord(recordType: &quot;Article&quot;)\narticleRecord[&quot;title&quot;] = &quot;CloudKit \u6559\u7a0b&quot; as CKRecord.Value\narticleRecord[&quot;author&quot;] = &quot;\u5f20\u4e09&quot; as CKRecord.Value\narticleRecord[&quot;publishDate&quot;] = Date() as CKRecord.Value\n\n\/\/ \u4fdd\u5b58\u5230\u6570\u636e\u5e93\nCKContainer.default().privateDatabase.save(articleRecord) { ... }<\/code><\/pre>\n<h3>2. <strong>\u6587\u4ef6\uff08Assets\uff09<\/strong><\/h3>\n<h4>\u672c\u8d28<\/h4>\n<p>\u6587\u4ef6\uff08CloudKit \u4e2d\u79f0\u4e3a <strong>CKAsset<\/strong>\uff09\u7528\u4e8e\u5b58\u50a8\u975e\u7ed3\u6784\u5316\u7684\u4e8c\u8fdb\u5236\u6570\u636e\uff0c\u5982\u56fe\u7247\u3001\u89c6\u9891\u3001\u6587\u6863\u7b49\u5927\u578b\u6587\u4ef6\u3002<\/p>\n<h4>\u5b58\u50a8\u65b9\u5f0f<\/h4>\n<ul>\n<li><strong>\u975e\u7ed3\u6784\u5316\u5b58\u50a8<\/strong>\uff1a\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u5b58\u50a8\uff0c\u65e0\u683c\u5f0f\u9650\u5236\uff08\u4efb\u610f\u6587\u4ef6\u7c7b\u578b\uff09\u3002<\/li>\n<li><strong>\u95f4\u63a5\u5173\u8054\u5230\u8bb0\u5f55<\/strong>\uff1a\u6587\u4ef6\u672c\u8eab\u4e0d\u76f4\u63a5\u5b58\u5728\u4e8e\u6570\u636e\u5e93\u4e2d\uff0c\u800c\u662f\u5b58\u50a8\u5728 CloudKit \u7684\u6587\u4ef6\u5b58\u50a8\u670d\u52a1\u4e2d\uff0c\u4ec5\u5728\u8bb0\u5f55\u4e2d\u4fdd\u5b58\u4e00\u4e2a<strong>\u5f15\u7528\uff08CKAsset \u5bf9\u8c61\uff09<\/strong> \u6307\u5411\u6587\u4ef6\u3002<\/li>\n<li><strong>\u5927\u5c0f\u9650\u5236<\/strong>\uff1a\u5355\u4e2a\u6587\u4ef6\u6700\u5927\u652f\u6301 <strong>50GB<\/strong>\uff08\u4f46\u5b9e\u9645\u53d7\u9650\u4e8e iCloud \u5b58\u50a8\u7a7a\u95f4\u548c\u7f51\u7edc\u6761\u4ef6\uff09\u3002<\/li>\n<\/ul>\n<h4>\u5178\u578b\u7528\u9014<\/h4>\n<ul>\n<li>\u56fe\u7247\uff08\u7528\u6237\u5934\u50cf\u3001\u76f8\u518c\u7167\u7247\uff09<\/li>\n<li>\u89c6\u9891\/\u97f3\u9891\uff08\u5f55\u5236\u7684\u89c6\u9891\u3001\u8bed\u97f3\u6d88\u606f\uff09<\/li>\n<li>\u6587\u6863\uff08PDF\u3001Excel \u7b49\u9644\u4ef6\uff09<\/li>\n<li>\u5176\u4ed6\u5927\u578b\u4e8c\u8fdb\u5236\u6570\u636e\uff08\u538b\u7f29\u5305\u3001\u5907\u4efd\u6587\u4ef6\uff09<\/li>\n<\/ul>\n<h4>\u64cd\u4f5c\u793a\u4f8b<\/h4>\n<pre><code class=\"language-swift\">\/\/ 1. \u51c6\u5907\u672c\u5730\u6587\u4ef6URL\uff08\u5982\u4e00\u5f20\u56fe\u7247\uff09\nguard let imageURL = Bundle.main.url(forResource: &quot;example&quot;, withExtension: &quot;png&quot;) else { return }\n\n\/\/ 2. \u521b\u5efaCKAsset\u5173\u8054\u6587\u4ef6\nlet imageAsset = CKAsset(fileURL: imageURL)\n\n\/\/ 3. \u5c06Asset\u5b58\u5165\u8bb0\u5f55\u7684\u5b57\u6bb5\u4e2d\nlet photoRecord = CKRecord(recordType: &quot;Photo&quot;)\nphotoRecord[&quot;image&quot;] = imageAsset as CKRecord.Value \/\/ \u5b58\u50a8\u7684\u662f\u5f15\u7528\uff0c\u800c\u975e\u6587\u4ef6\u672c\u8eab\nphotoRecord[&quot;caption&quot;] = &quot;\u65c5\u884c\u7167\u7247&quot; as CKRecord.Value\n\n\/\/ 4. \u4fdd\u5b58\u8bb0\u5f55\uff08\u6587\u4ef6\u4f1a\u81ea\u52a8\u4e0a\u4f20\u5230CloudKit\u7684\u6587\u4ef6\u5b58\u50a8\uff09\nCKContainer.default().privateDatabase.save(photoRecord) { ... }<\/code><\/pre>\n<h3>\u6838\u5fc3\u533a\u522b\u603b\u7ed3<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u7ef4\u5ea6<\/th>\n<th>\u8bb0\u5f55\uff08Records\uff09<\/th>\n<th>\u6587\u4ef6\uff08Assets\uff09<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6570\u636e\u7c7b\u578b<\/td>\n<td>\u7ed3\u6784\u5316\u6570\u636e\uff08\u6587\u672c\u3001\u6570\u5b57\u3001\u65e5\u671f\u7b49\uff09<\/td>\n<td>\u975e\u7ed3\u6784\u5316\u4e8c\u8fdb\u5236\u6570\u636e\uff08\u56fe\u7247\u3001\u89c6\u9891\u7b49\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u5b58\u50a8\u4f4d\u7f6e<\/td>\n<td>\u76f4\u63a5\u5b58\u50a8\u5728 CloudKit \u6570\u636e\u5e93\u4e2d<\/td>\n<td>\u5b58\u50a8\u5728\u6587\u4ef6\u670d\u52a1\uff0c\u8bb0\u5f55\u4e2d\u4ec5\u5b58\u5f15\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u5927\u5c0f\u9650\u5236<\/td>\n<td>\u5355\u6761\u8bb0\u5f55 \u2264 1MB<\/td>\n<td>\u5355\u4e2a\u6587\u4ef6 \u2264 50GB<\/td>\n<\/tr>\n<tr>\n<td>\u8bbf\u95ee\u65b9\u5f0f<\/td>\n<td>\u76f4\u63a5\u4ece\u8bb0\u5f55\u5b57\u6bb5\u8bfb\u53d6<\/td>\n<td>\u901a\u8fc7\u8bb0\u5f55\u4e2d\u7684 CKAsset \u5f15\u7528\u52a0\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>\u9002\u7528\u573a\u666f<\/td>\n<td>\u5c0f\u578b\u7ed3\u6784\u5316\u6570\u636e<\/td>\n<td>\u5927\u578b\u6587\u4ef6\u6216\u4e8c\u8fdb\u5236\u6570\u636e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u6700\u4f73\u5b9e\u8df5<\/h3>\n<ul>\n<li>\u7528<strong>\u8bb0\u5f55<\/strong>\u5b58\u50a8\u7ed3\u6784\u5316\u5143\u6570\u636e\uff0c\u7528<strong>\u6587\u4ef6<\/strong>\u5b58\u50a8\u5927\u578b\u4e8c\u8fdb\u5236\u5185\u5bb9\uff08\u5982\u4e00\u6761&quot;\u670b\u53cb\u5708&quot;\u8bb0\u5f55\u4e2d\uff0c\u6587\u5b57\u5185\u5bb9\u5b58\u5728\u8bb0\u5f55\u5b57\u6bb5\uff0c\u914d\u56fe\u7528 CKAsset \u5b58\u50a8\uff09\u3002<\/li>\n<li>\u907f\u514d\u5728\u8bb0\u5f55\u4e2d\u5b58\u50a8\u5927\u91cf\u6587\u672c\uff08\u5982\u6574\u7bc7\u6587\u7ae0\uff09\uff0c\u8d85\u8fc7 1MB \u9700\u62c6\u5206\u4e3a\u8bb0\u5f55+\u6587\u4ef6\u3002<\/li>\n<li>\u8bfb\u53d6\u6587\u4ef6\u65f6\u6ce8\u610f\u7f51\u7edc\u72b6\u6001\uff0c\u5efa\u8bae\u5b9e\u73b0\u672c\u5730\u7f13\u5b58\uff08\u5982\u4e0b\u8f7d\u540e\u4fdd\u5b58\u5230\u6c99\u76d2\uff0c\u907f\u514d\u91cd\u590d\u4e0b\u8f7d\uff09\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8fd9\u79cd\u5206\u79bb\u8bbe\u8ba1\uff0cCloudKit \u65e2\u80fd\u9ad8\u6548\u7ba1\u7406\u7ed3\u6784\u5316\u6570\u636e\uff0c\u53c8\u80fd\u7075\u6d3b\u5904\u7406\u5927\u578b\u6587\u4ef6\uff0c\u517c\u987e\u4e86\u6027\u80fd\u548c\u6269\u5c55\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 CloudKit \u4e2d\uff0c\u8bb0\u5f55\uff08Records\uff09 \u548c\u6587\u4ef6\uff08Files\/Assets\uff09 \u662f\u4e24\u79cd\u4e0d\u540c\u7684\u6570\u636e\u5b58\u50a8\u65b9\u5f0f&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6873\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[160,66],"class_list":["post-6873","post","type-post","status-publish","format-standard","hentry","category-135","tag-cloudkit","tag-ios"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6873"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6873\/revisions"}],"predecessor-version":[{"id":6874,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6873\/revisions\/6874"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}