{"id":190892,"date":"2022-09-16T05:11:30","date_gmt":"2022-09-15T21:11:30","guid":{"rendered":"https:\/\/www.idc.net\/help\/190892\/"},"modified":"2022-09-16T05:11:30","modified_gmt":"2022-09-15T21:11:30","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91ios%e6%95%99%e7%a8%8b%ef%bc%9a%e9%82%80%e8%af%b7%e5%8f%82%e4%b8%8e%e8%80%85%e5%85%b1%e4%ba%ab%e6%b4%bb%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/190892\/","title":{"rendered":"\u540e\u6d6a\u4e91IOS\u6559\u7a0b\uff1a\u9080\u8bf7\u53c2\u4e0e\u8005\u5171\u4eab\u6d3b\u52a8"},"content":{"rendered":"<h2> \u6982\u89c8 <\/h2>\n<p> \u521b\u5efa\u7fa4\u7ec4\u4f53\u9a8c\u65f6\uff0c\u5e94\u8be5\u4ee5\u4f60\u7684 App \u6240\u652f\u6301\u7684\u6d3b\u52a8\u4e3a\u4e2d\u5fc3\u3002\u4f8b\u5982\uff0c\u89c6\u9891\u6d41 App \u53ef\u4ee5\u5b9a\u4e49\u89c2\u5f71\u6d3b\u52a8\u3002\u6d3b\u52a8\u5305\u542b App \u6267\u884c\u76f8\u5173\u4efb\u52a1 (\u5982\u64ad\u653e\u5f71\u7247) \u6240\u9700\u7684\u6570\u636e\u3002\u5b83\u8fd8\u5305\u62ec\u5173\u4e8e\u6d3b\u52a8\u7684\u63cf\u8ff0\u4fe1\u606f (\u5982\u5f71\u7247\u7684\u540d\u79f0)\uff0c\u7cfb\u7edf\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u4fe1\u606f\u4f20\u8fbe\u7ed9\u5176\u4ed6\u53c2\u4e0e\u8005\u3002 <\/p>\n<p> \u901a\u8fc7 Group Activities \u6846\u67b6\uff0c\u4f60\u53ef\u4ee5\u5c06\u6d3b\u52a8\u4fe1\u606f\u6574\u5408\u5230 App \u7684\u73b0\u6709\u7c7b\u578b\u548c\u5bf9\u8c61\u4e2d\u3002\u4e3a\u4f60\u7684 App \u652f\u6301\u7684\u6bcf\u4e2a\u72ec\u7279\u4f53\u9a8c\u5b9a\u4e49\u4e00\u9879\u6d3b\u52a8\u3002\u4f8b\u5982\uff0c\u89c6\u9891\u6d41 App \u53ef\u4ee5\u5206\u522b\u4e3a\u89c2\u5f71\u548c\u89c2\u770b\u7535\u89c6\u8282\u76ee\u5b9a\u4e49\u4e0d\u540c\u7684\u6d3b\u52a8\u3002\u901a\u8fc7\u5206\u522b\u4f7f\u7528\u4e0d\u540c\u7684\u6d3b\u52a8\u7c7b\u578b\uff0c\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u4e3a\u6bcf\u9879\u6d3b\u52a8\u5b9a\u5236\u4f53\u9a8c\u3002 <\/p>\n<h3> \u914d\u7f6e\u6388\u6743 <\/h3>\n<p> \u7531\u4e8e\u6d3b\u52a8\u6d89\u53ca\u4e0e\u5176\u4ed6\u8bbe\u5907\u7684\u4ea4\u4e92\uff0c\u56e0\u6b64\u4f60\u7684 App \u5fc5\u987b\u5177\u6709 <code>com.apple.developer.group-session<\/code> (\u82f1\u6587) \u6388\u6743\u3002\u5728 Xcode \u4e2d\u5c06\u6b64\u6388\u6743\u6dfb\u52a0\u5230\u4f60\u7684 App\uff1a <\/p>\n<ol>\n<li>\n<p> \u6253\u5f00\u4f60\u7684 Xcode \u9879\u76ee\u3002 <\/p>\n<\/li>\n<li>\n<p> \u9009\u62e9\u4f60\u7684 App \u76ee\u6807\u3002 <\/p>\n<\/li>\n<li>\n<p> \u524d\u5f80\u201cSigning &amp; Capabilities\u201d(\u7b7e\u540d\u548c\u529f\u80fd) \u6807\u7b7e\u3002 <\/p>\n<\/li>\n<li>\n<p> \u5c06\u7fa4\u7ec4\u6d3b\u52a8\u529f\u80fd\u6dfb\u52a0\u5230\u76f8\u5e94\u76ee\u6807\u4e2d\u3002 <\/p>\n<\/li>\n<\/ol>\n<p> \u7fa4\u7ec4\u6d3b\u52a8\u529f\u80fd\u4f1a\u5c06\u5fc5\u8981\u7684\u6388\u6743\u6dfb\u52a0\u5230\u4f60\u7684 App \u548c\u9884\u7f6e\u63cf\u8ff0\u6587\u4ef6\u4e2d\u3002\u4f60\u53ef\u4ee5\u5c06\u6b64\u529f\u80fd\u4ec5\u6dfb\u52a0\u5230 App \u76ee\u6807\u3002 <\/p>\n<h3> \u5b9a\u4e49\u81ea\u5b9a\u6d3b\u52a8\u5b9e\u4f8b <\/h3>\n<p> \u5bf9\u4e8e App \u652f\u6301\u7684\u6bcf\u9879\u6d3b\u52a8\uff0c\u5b9a\u4e49\u91c7\u7528 <code>GroupActivity<\/code> (\u82f1\u6587) \u534f\u8bae\u7684\u8f7b\u91cf\u7ea7\u7c7b\u6216\u7ed3\u6784\u3002\u6d3b\u52a8\u5b9e\u4f8b\u63d0\u4f9b App \u5411\u53c2\u4e0e\u8005\u63d0\u4f9b\u7684\u7279\u5b9a\u6d3b\u52a8\u76f8\u5173\u63cf\u8ff0\u4fe1\u606f\u3002\u6d3b\u52a8\u5b9e\u4f8b\u5b9e\u9645\u4e0a\u53ef\u80fd\u662f App \u4e2d\u7684\u73b0\u6709\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u89c2\u5f71 App \u7684\u6d3b\u52a8\u5b9e\u4f8b\u53ef\u80fd\u5305\u542b\u5f71\u7247\u540d\u79f0\u3001\u6d77\u62a5\u56fe\u50cf\u4ee5\u53ca\u5173\u4e8e\u5982\u4f55\u64ad\u653e\u5f71\u7247\u7684\u7279\u5b9a\u4e8e App \u7684\u4fe1\u606f\u3002 <\/p>\n<p> \u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u4e3a\u89c2\u5f71\u6d3b\u52a8\u63d0\u4f9b\u652f\u6301\u7684\u7ed3\u6784\u7684\u5b9e\u73b0\u3002<code>activityIdentifier<\/code> \u5c5e\u6027\u5305\u542b\u4f60\u7684\u6d3b\u52a8\u7684\u552f\u4e00\u6807\u8bc6\u7b26\uff0c\u901a\u5e38\u91c7\u7528\u53cd\u5411 DNS \u683c\u5f0f\u3002\u5176\u4ed6\u5c5e\u6027\u5219\u4f1a\u5b9a\u4e49\u5173\u4e8e\u5f71\u7247\u7684\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u8fd9\u4e2a App \u4f7f\u7528 <code>catalog<\/code> \u548c <code>contentIdentifier<\/code> \u5c5e\u6027\u5728 iTunes Store \u4e2d\u67e5\u627e\u5f71\u7247\u3002 <\/p>\n<pre><code><span><span><\/span> <span><span>struct<\/span> <span>WatchTogether<\/span>: <span>GroupActivity<\/span> {<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span> <span>\/\/ Specify the activity type to the system.<\/span><\/span><\/span><span><span><\/span> <span> <span>static<\/span> <span>let<\/span> activityIdentifier <span>=<\/span> \u201ccom.example.myapp.watch<span>-<\/span>movie<span>-<\/span>together\u201d<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span> <span>\/\/----------<\/span><\/span><\/span><span><span><\/span> <span> <span>\/\/ Store app-specific information about the movie. <\/span><\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span> <span>\/\/ The catalog identifier or store location of the content.<\/span><\/span><\/span><span><span><\/span> <span> <span>var<\/span> catalog: <span>Catalog<\/span> <span>=<\/span> .us<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span> <span>\/\/ The content item identifier of the movie to watch together.<\/span><\/span><\/span><span><span><\/span> <span> <span>var<\/span> contentIdentifier: <span>String<\/span><\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span> <span>\/\/ The movie title localized to the initiator's language.<\/span><\/span><\/span><span><span><\/span> <span> <span>var<\/span> movieTitle: <span>String<\/span><\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span>}<\/span><\/span><\/code>\n<\/pre>\n<p> \u53ea\u6709\u5f53\u4f60\u7684 App \u5411\u7528\u6237\u5c55\u793a\u6d3b\u52a8\u65f6\uff0c\u8fd9\u4e9b\u6d3b\u52a8\u624d\u662f\u76f8\u5173\u7684\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u5728\u7528\u6237\u754c\u9762\u8bbe\u7f6e\u65f6\u521b\u5efa <code>GroupActivity<\/code> (\u82f1\u6587) \u7c7b\u578b\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u5728\u89c6\u56fe\u4e2d\u3002\u4f8b\u5982\uff0c\u5728\u5f71\u7247\u8be6\u60c5\u89c6\u56fe\u4e2d\u521b\u5efa\u4e00\u4e2a\u4e0a\u8ff0\u7c7b\u578b\uff0c\u8be5\u89c6\u56fe\u663e\u793a\u4f9b\u53c2\u4e0e\u8005\u89c2\u770b\u7684\u5f71\u7247\u3002 <\/p>\n<h3> \u63d0\u4f9b\u5173\u4e8e\u6d3b\u52a8\u7684\u63cf\u8ff0\u4fe1\u606f <\/h3>\n<p> \u5728\u7528\u6237\u52a0\u5165\u6d3b\u52a8\u4e4b\u524d\uff0c\u7cfb\u7edf\u4f1a\u663e\u793a\u8be5\u6d3b\u52a8\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u6807\u9898\u3001\u53ef\u9009\u7684\u526f\u6807\u9898\u4ee5\u53ca\u8981\u663e\u793a\u7684\u56fe\u50cf\u3002\u89c2\u5f71 App \u53ef\u80fd\u4f1a\u8fd4\u56de\u5f71\u7247\u540d\u79f0\u53ca\u5176\u76f8\u5173\u6d77\u62a5\u56fe\u50cf\u3002\u542c\u6b4c App \u53ef\u80fd\u4f1a\u8fd4\u56de\u6240\u9009\u66f2\u76ee\u7684\u540d\u79f0\u548c\u4efb\u4f55\u4e13\u8f91\u63d2\u56fe\u3002 <\/p>\n<p> \u8981\u5c06\u6d3b\u52a8\u7684\u5143\u6570\u636e\u8fd4\u56de\u7ed9\u7cfb\u7edf\uff0c\u9700\u5b9e\u73b0 <code>metadata<\/code> (\u82f1\u6587) \u5c5e\u6027\u5e76\u8fd4\u56de <code>GroupActivityMetadata<\/code> (\u82f1\u6587) \u5b9e\u4f8b\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86 <code>WatchTogether<\/code> \u7ed3\u6784\u7684\u4e00\u4e2a\u6269\u5c55\uff0c\u5176\u4e2d\u521b\u5efa\u4e86\u8fd9\u4e00\u7ed3\u6784\u5e76\u5c06\u5f71\u7247\u6807\u9898\u586b\u5165\u5176\u4e2d\u3002\u5b83\u8fd8\u5305\u542b\u4e00\u4e2a\u57fa\u4e8e web \u7684 URL\uff0c\u4f9b\u5c1a\u672a\u5728\u8bbe\u5907\u4e0a\u5b89\u88c5\u4f60\u7684 App \u7684\u53c2\u4e0e\u8005\u4f7f\u7528\u3002 <\/p>\n<pre><code><span><span><\/span> <span><span>extension<\/span> <span>WatchTogether<\/span> {<\/span><\/span><span><span><\/span> <span> <\/span><\/span><span><span><\/span> <span> <span>\/\/ Provide information about the activity. <\/span><\/span><\/span><span><span><\/span> <span> <span>var<\/span> metadata: <span>GroupActivityMetadata<\/span> {<\/span><\/span><span><span><\/span> <span> <span>var<\/span> metadata <span>=<\/span> <span>GroupActivityMetadata<\/span>()<\/span><\/span><span><span><\/span> <span> metadata.type <span>=<\/span> .watchTogether<\/span><\/span><span><span><\/span> <span> metadata.title <span>=<\/span> movieTitle<\/span><\/span><span><span><\/span> <span> metadata.fallbackURL <span>=<\/span> <span>URL<\/span>(string: <\/span><\/span><span><span><\/span> <span> <span>\"https:\/\/itunes.apple.com\/<span>\\(catalog)<\/span>\/movie\/<span>\\(contentIdentifier)<\/span>\"<\/span>)<\/span><\/span><span><span><\/span> <span> <span>return<\/span> metadata<\/span><\/span><span><span><\/span> <span> }<\/span><\/span><span><span><\/span> <span>}<\/span><\/span><\/code>\n<\/pre>\n<h3> \u63d0\u4f9b\u52a0\u5165\u6d3b\u52a8\u6240\u9700\u7684 UI <\/h3>\n<p> \u5728 App \u7684 UI \u4e2d\u52a0\u5165\u6309\u94ae\u6216\u5176\u4ed6\u63a7\u4ef6\uff0c\u8ba9\u7528\u6237\u80fd\u591f\u542f\u52a8\u65b0\u6d3b\u52a8\u3002\u5f53\u7528\u6237\u8f7b\u70b9\u76f8\u5e94\u6309\u94ae\uff0c\u6216\u8005\u4ee5\u542f\u52a8\u6d3b\u52a8\u7684\u65b9\u5f0f\u4e0e UI \u4ea4\u4e92\u65f6\uff0c\u8c03\u7528\u76f8\u5173 <code>GroupActivity<\/code> (\u82f1\u6587) \u7c7b\u578b\u7684\u9002\u5f53\u65b9\u6cd5\u3002 <\/p>\n<p> \u5bf9\u4e8e\u5927\u591a\u6570\u6d3b\u52a8\uff0c\u4f60\u53ef\u4ee5\u8c03\u7528 <code>GroupActivity<\/code> (\u82f1\u6587) \u7c7b\u578b\u7684 <code>prepareForActivation()<\/code> (\u82f1\u6587) \u65b9\u6cd5\u6765\u542f\u52a8\u6d3b\u52a8\u3002\u8be5\u65b9\u6cd5\u53ef\u786e\u5b9a App \u662f\u5426\u652f\u6301\u6d3b\u52a8\u5171\u4eab\uff0c\u4ee5\u53ca\u7528\u6237\u662f\u5426\u5e0c\u671b\u5171\u4eab\u6d3b\u52a8\u3002\u4f8b\u5982\uff0c\u7528\u6237\u53ef\u80fd\u9009\u62e9\u89c2\u770b\u5f71\u7247\u800c\u4e0d\u4e0e\u670b\u53cb\u5171\u4eab\u3002\u5f53\u7ed3\u679c\u5c31\u7eea\u65f6\uff0c\u8be5\u65b9\u6cd5\u8c03\u7528\u4f60\u63d0\u4f9b\u7684\u5b8c\u6210\u5904\u7406\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u542f\u52a8\u6216\u4e2d\u6b62\u6d3b\u52a8\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5b9e\u73b0\u5bf9\u8be5\u65b9\u6cd5\u7684\u5178\u578b\u8c03\u7528\uff1a <\/p>\n<pre><code><span><span><\/span> <span><span>private<\/span> <span>func<\/span> <span>playMovie<\/span>() {<\/span><\/span><span><span><\/span> <span> <span>\/\/ If a session is already active, just change the movie.<\/span><\/span><\/span><span><span><\/span> <span> <span>if<\/span> <span>let<\/span> activeGroupSession <span>=<\/span> activitySession.groupSession {<\/span><\/span><span><span><\/span> <span> <span>\/\/ Change the current movie.<\/span><\/span><\/span><span><span><\/span> <span> activeGroupSession.activity <span>=<\/span> currentMovie<\/span><\/span><span><span><\/span> <span> } <span>else<\/span> {<\/span><\/span><span><span><\/span> <span> <span>\/\/ Try to start a new movie-watching activity.<\/span><\/span><\/span><span><span><\/span> <span> item.prepareForActivation { result <span>in<\/span><\/span><\/span><span><span><\/span> <span> <span>switch<\/span> result {<\/span><\/span><span><span><\/span> <span> <span>case<\/span> .activationPreferred:<\/span><\/span><span><span><\/span> <span> <span>\/\/ Watch the movie with the group.<\/span><\/span><\/span><span><span><\/span> <span> currentMovie.activate()<\/span><\/span><span><span><\/span> <span> <span>case<\/span> .activationDisabled:<\/span><\/span><span><span><\/span> <span> <span>\/\/ Watch the movie locally. <\/span><\/span><\/span><span><span><\/span> <span> isMoviePlaying <span>=<\/span> <span>true<\/span><\/span><\/span><span><span><\/span> <span> <span>default<\/span>:<\/span><\/span><span><span><\/span> <span> <span>break<\/span><\/span><\/span><span><span><\/span> <span> }<\/span><\/span><span><span><\/span> <span> }<\/span><\/span><span><span><\/span> <span> }<\/span><\/span><span><span><\/span> <span>}<\/span><\/span><\/code>\n<\/pre>\n<p> \u6ce8\u91ca <\/p>\n<p> \u5982\u679c\u4f60\u7684\u6d3b\u52a8\u4ec5\u9002\u5408\u5e94\u7528\u4e8e\u7fa4\u7ec4\u73af\u5883\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528 <code>activate()<\/code> (\u82f1\u6587) \u65b9\u6cd5\uff0c\u800c\u65e0\u9700\u51c6\u5907\u6fc0\u6d3b\u3002 <\/p>\n<p> \u8981\u8fdb\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u52a0\u5165\u65b0\u542f\u52a8\u7684\u6d3b\u52a8\uff0c\u8bf7\u53c2\u9605\u201c\u52a0\u5165\u548c\u7ba1\u7406\u5171\u4eab\u6d3b\u52a8\u201d\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u89c8 \u521b\u5efa\u7fa4\u7ec4\u4f53\u9a8c\u65f6\uff0c\u5e94\u8be5\u4ee5\u4f60\u7684 App \u6240\u652f\u6301\u7684\u6d3b\u52a8\u4e3a\u4e2d\u5fc3\u3002\u4f8b\u5982\uff0c\u89c6\u9891\u6d41 App \u53ef\u4ee5\u5b9a\u4e49\u89c2\u5f71\u6d3b\u52a8\u3002\u6d3b\u52a8\u5305\u542b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189686],"tags":[],"class_list":["post-190892","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=190892"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190892\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=190892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=190892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=190892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}