{"id":6956,"date":"2025-12-27T11:37:04","date_gmt":"2025-12-27T03:37:04","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6956"},"modified":"2025-12-27T11:37:04","modified_gmt":"2025-12-27T03:37:04","slug":"shareextension-%e5%a6%82%e4%bd%95%e5%bc%80%e5%8f%91%ef%bc%8c%e8%83%bd%e4%bb%8eios-%e5%93%aa%e4%ba%9b%e5%85%a5%e5%8f%a3%e6%8b%bf%e5%88%b0%e7%94%b5%e5%ad%90%e4%b9%a6%e7%b1%bb%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6956","title":{"rendered":"ShareExtension \u5982\u4f55\u5f00\u53d1\uff0c\u80fd\u4eceiOS \u54ea\u4e9b\u5165\u53e3\u62ff\u5230\u7535\u5b50\u4e66\u7c7b\u6587\u4ef6"},"content":{"rendered":"<p>\u6211\u76f4\u63a5\u6309<strong>\u201c\u4f60\u8981\u771f\u505a\u4e00\u4e2a\u7535\u5b50\u4e66\u5de5\u5177\u578b App\u201d<\/strong>\u7684\u5b9e\u6218\u89c6\u89d2\u7ed9\u4f60\u8bb2\uff0c\u4e0d\u7ed5\u6982\u5ff5\u3002<\/p>\n<hr \/>\n<h2>\u4e00\u3001Share Extension \u662f\u4ec0\u4e48\uff08\u4e00\u53e5\u8bdd\u7248\uff09<\/h2>\n<p><strong>Share Extension = \u4ece\u7cfb\u7edf\u4efb\u610f\u201c\u5206\u4eab\u201d\u5165\u53e3\uff0c\u628a\u6587\u4ef6\/\u5185\u5bb9\u201c\u585e\u8fdb\u4f60\u7684 App\u201d<\/strong><br \/>\n\u5bf9\u7535\u5b50\u4e66 App \u6765\u8bf4\uff0c\u5b83\u662f<strong>\u6700\u4f4e\u6210\u672c\u83b7\u53d6\u7528\u6237\u6587\u4ef6\u7684\u6838\u5fc3\u5165\u53e3<\/strong>\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u3001\u7535\u5b50\u4e66\u7c7b\u6587\u4ef6\uff1aShare Extension \u80fd\u4ece iOS \u54ea\u4e9b\u5165\u53e3\u62ff\u5230\uff1f<\/h2>\n<p>\u4e0b\u9762\u662f<strong>\u771f\u5b9e\u53ef\u884c + \u5e02\u573a\u5e38\u89c1<\/strong>\u7684\u5165\u53e3\uff0c\u6309\u91cd\u8981\u6027\u6392\u5e8f \ud83d\udc47<\/p>\n<hr \/>\n<h3>\u2705 1\ufe0f\u20e3 Files\uff08\u6587\u4ef6 App\uff09\u3010\u6700\u91cd\u8981\u3011<\/h3>\n<p><strong>\u652f\u6301\u6765\u6e90<\/strong><\/p>\n<ul>\n<li>iCloud Drive<\/li>\n<li>\u672c\u5730\u201c\u6211\u7684 iPhone \/ iPad\u201d<\/li>\n<li>\u7b2c\u4e09\u65b9\u4e91\u76d8\uff08Google Drive\u3001Dropbox\u3001OneDrive\uff09<\/li>\n<li>SMB \/ WebDAV<\/li>\n<\/ul>\n<p><strong>\u7528\u6237\u64cd\u4f5c<\/strong><\/p>\n<pre><code>Files \u2192 \u957f\u6309\u6587\u4ef6 \u2192 \u5206\u4eab \u2192 \u4f60\u7684 App<\/code><\/pre>\n<p><strong>\u53ef\u62ff\u5230\u7684\u7535\u5b50\u4e66\u7c7b\u578b<\/strong><\/p>\n<ul>\n<li><code>.txt<\/code><\/li>\n<li><code>.epub<\/code><\/li>\n<li><code>.pdf<\/code><\/li>\n<li><code>.md<\/code><\/li>\n<li><code>.mobi<\/code>\uff08\u6709\u4e9b\u4e91\u76d8\u4f1a\u7ed9\uff0c\u4f46\u4f60\u662f\u5426\u652f\u6301\u53e6\u8bf4\uff09<\/li>\n<li><code>.zip<\/code>\uff08\u7535\u5b50\u4e66\u6253\u5305\uff09<\/li>\n<\/ul>\n<p>\ud83d\udc49 <strong>\u8fd9\u662f\u7535\u5b50\u4e66\u7c7b App \u7684\u547d\u8109\u5165\u53e3<\/strong><\/p>\n<hr \/>\n<h3>\u2705 2\ufe0f\u20e3 Safari\uff08\u4e0b\u8f7d \/ \u6253\u5f00 in\u2026\uff09<\/h3>\n<p>Safari \u662f<strong>\u7b2c\u4e8c\u5927\u7535\u5b50\u4e66\u6765\u6e90<\/strong>\u3002<\/p>\n<h4>\u573a\u666f A\uff1aSafari \u4e0b\u8f7d<\/h4>\n<ul>\n<li>\n<p>\u7528\u6237\u4e0b\u8f7d\uff1a<\/p>\n<ul>\n<li>TXT \/ EPUB \/ PDF<\/li>\n<\/ul>\n<\/li>\n<li>\u4e0b\u8f7d\u5b8c\u6210\u540e \u2192 <strong>\u5206\u4eab \u2192 \u4f60\u7684 App<\/strong><\/li>\n<\/ul>\n<h4>\u573a\u666f B\uff1a\u7f51\u9875\u76f4\u5f00\u6587\u4ef6<\/h4>\n<ul>\n<li>\u6709\u4e9b\u7ad9\u70b9\u76f4\u63a5\u6253\u5f00 PDF \/ TXT<\/li>\n<li>\u53f3\u4e0a\u89d2\u5206\u4eab \u2192 \u4f60\u7684 App<\/li>\n<\/ul>\n<p>\ud83d\udc49 \u975e\u5e38\u9002\u5408\uff1a<\/p>\n<ul>\n<li>\u516c\u7248\u4e66<\/li>\n<li>\u6280\u672f\u6587\u6863<\/li>\n<li>\u5b66\u672f PDF<\/li>\n<\/ul>\n<hr \/>\n<h3>\u2705 3\ufe0f\u20e3 \u7b2c\u4e09\u65b9 App\uff08\u5fae\u4fe1 \/ Telegram \/ \u90ae\u4ef6 \/ \u7f51\u76d8\uff09<\/h3>\n<h4>\u5e38\u89c1\u6765\u6e90<\/h4>\n<ul>\n<li>Mail\uff08\u9644\u4ef6\uff09<\/li>\n<li>Telegram\uff08\u6587\u6863\uff09<\/li>\n<li>LINE \/ WhatsApp\uff08\u6587\u4ef6\uff09<\/li>\n<li>Google Drive \/ Dropbox App \u5185<\/li>\n<\/ul>\n<p><strong>\u524d\u63d0<\/strong><\/p>\n<ul>\n<li>\u5bf9\u65b9 App \u7528\u7684\u662f\u6807\u51c6 <code>UIActivityViewController<\/code><\/li>\n<li>\u6587\u4ef6\u7c7b\u578b\u6ca1\u88ab\u5b83\u201c\u79c1\u6709\u5316\u201d<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u4f60\u62ff\u5230\u7684\u4e00\u5b9a\u662f\u6587\u4ef6 URL\uff08\u4e34\u65f6\u6c99\u76d2\uff09<\/strong><\/p>\n<hr \/>\n<h3>\u26a0\ufe0f 4\ufe0f\u20e3 Books\uff08Apple Books\uff09\u3010\u51e0\u4e4e\u4e0d\u53ef\u80fd\u3011<\/h3>\n<p>\u7ed3\u8bba\u5148\u7ed9\u4f60\uff1a<\/p>\n<blockquote>\n<p>\u274c <strong>\u65e0\u6cd5\u4ece Apple Books Share \u51fa EPUB\/PDF \u539f\u6587\u4ef6<\/strong><\/p>\n<\/blockquote>\n<p>\u539f\u56e0\uff1a<\/p>\n<ul>\n<li>DRM<\/li>\n<li>Books \u4e0d\u66b4\u9732\u6587\u4ef6\u7ea7 Share<\/li>\n<li>\u53ea\u5141\u8bb8\u201c\u5206\u4eab\u5185\u5bb9\u5f15\u7528\u201d<\/li>\n<\/ul>\n<p>\ud83d\udc49 <strong>\u522b\u6307\u671b\u8fd9\u4e2a\u5165\u53e3<\/strong><\/p>\n<hr \/>\n<h3>\u26a0\ufe0f 5\ufe0f\u20e3 Kindle \/ \u5fae\u4fe1\u8bfb\u4e66 \/ \u638c\u9605<\/h3>\n<p>\u7ed3\u8bba\u7edf\u4e00\uff1a<\/p>\n<blockquote>\n<p>\u274c <strong>\u51e0\u4e4e\u62ff\u4e0d\u5230\u539f\u6587\u4ef6<\/strong><\/p>\n<\/blockquote>\n<p>\u5b83\u4eec\u53ea\u4f1a\uff1a<\/p>\n<ul>\n<li>\u5206\u4eab\u4e66\u540d \/ \u94fe\u63a5 \/ \u56fe\u7247<\/li>\n<li>\u4e0d\u4f1a\u5206\u4eab <code>.epub\/.mobi<\/code><\/li>\n<\/ul>\n<hr \/>\n<h2>\u4e09\u3001Share Extension \u6280\u672f\u5b9e\u73b0\uff08\u4f60\u771f\u6b63\u8981\u5199\u7684\uff09<\/h2>\n<h3>1\ufe0f\u20e3 \u65b0\u5efa Share Extension Target<\/h3>\n<p>Xcode\uff1a<\/p>\n<pre><code>File \u2192 New \u2192 Target \u2192 Share Extension<\/code><\/pre>\n<p>\u7cfb\u7edf\u4f1a\u7ed9\u4f60\uff1a<\/p>\n<ul>\n<li><code>ShareViewController<\/code><\/li>\n<li>\u72ec\u7acb Bundle<\/li>\n<li>\u72ec\u7acb Info.plist<\/li>\n<\/ul>\n<hr \/>\n<h3>2\ufe0f\u20e3 Info.plist\uff1a\u58f0\u660e\u4f60\u652f\u6301\u7684\u7535\u5b50\u4e66\u7c7b\u578b\uff08\u5173\u952e\uff09<\/h3>\n<p>\u4f60\u81f3\u5c11\u8981\u52a0\u8fd9\u4e9b UTI \ud83d\udc47<\/p>\n<pre><code class=\"language-xml\">&lt;key&gt;NSExtension&lt;\/key&gt;\n&lt;dict&gt;\n  &lt;key&gt;NSExtensionAttributes&lt;\/key&gt;\n  &lt;dict&gt;\n    &lt;key&gt;NSExtensionActivationRule&lt;\/key&gt;\n    &lt;dict&gt;\n      &lt;key&gt;NSExtensionActivationSupportsFileWithMaxCount&lt;\/key&gt;\n      &lt;integer&gt;10&lt;\/integer&gt;\n\n      &lt;key&gt;NSExtensionActivationSupportsAttachmentsWithContentTypes&lt;\/key&gt;\n      &lt;array&gt;\n        &lt;string&gt;public.plain-text&lt;\/string&gt;     &lt;!-- txt --&gt;\n        &lt;string&gt;org.idpf.epub-container&lt;\/string&gt; &lt;!-- epub --&gt;\n        &lt;string&gt;com.adobe.pdf&lt;\/string&gt;          &lt;!-- pdf --&gt;\n        &lt;string&gt;public.zip-archive&lt;\/string&gt;\n      &lt;\/array&gt;\n    &lt;\/dict&gt;\n  &lt;\/dict&gt;\n&lt;\/dict&gt;<\/code><\/pre>\n<p>\ud83d\udccc <strong>\u4e0d\u5199\u5bf9 \u2192 \u7cfb\u7edf\u6839\u672c\u4e0d\u4f1a\u663e\u793a\u4f60\u7684 App<\/strong><\/p>\n<hr \/>\n<h3>3\ufe0f\u20e3 \u4ece Extension \u91cc\u62ff\u6587\u4ef6\uff08\u6838\u5fc3\u4ee3\u7801\uff09<\/h3>\n<pre><code class=\"language-swift\">let item = extensionContext?.inputItems.first as? NSExtensionItem\nlet providers = item?.attachments ?? []\n\nfor provider in providers {\n    if provider.hasItemConformingToTypeIdentifier(&quot;org.idpf.epub-container&quot;) {\n        provider.loadItem(forTypeIdentifier: &quot;org.idpf.epub-container&quot;, options: nil) { item, error in\n            if let url = item as? URL {\n                \/\/ \u8fd9\u662f\u7535\u5b50\u4e66\u6587\u4ef6\n            }\n        }\n    }\n}<\/code><\/pre>\n<p>\u26a0\ufe0f \u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u62ff\u5230\u7684\u662f<strong>\u4e34\u65f6\u6c99\u76d2 URL<\/strong><\/li>\n<li>Extension \u7ed3\u675f\u540e\u4f1a\u5931\u6548<\/li>\n<\/ul>\n<hr \/>\n<h3>4\ufe0f\u20e3 \u6b63\u786e\u505a\u6cd5\uff1a\u7acb\u523b\u62f7\u8d1d\u5230 App Group<\/h3>\n<pre><code class=\"language-swift\">let fm = FileManager.default\nlet groupURL = fm.containerURL(\n    forSecurityApplicationGroupIdentifier: &quot;group.your.app&quot;\n)!\n\nlet dest = groupURL.appendingPathComponent(url.lastPathComponent)\ntry fm.copyItem(at: url, to: dest)<\/code><\/pre>\n<p>\u4e3b App \u518d\u4ece App Group \u8bfb\u5165 \u2192 \u5165\u5e93 \u2192 \u89e3\u6790\u3002<\/p>\n<hr \/>\n<h2>\u56db\u3001\u7535\u5b50\u4e66 App \u7684\u300c\u6700\u4f73 Share Extension \u8bbe\u8ba1\u300d<\/h2>\n<p>\u7ed3\u5408\u4f60\u4e4b\u524d\u7684\u4ea7\u54c1\u65b9\u5411\uff0c\u6211\u76f4\u63a5\u7ed9\u4f60\u4e00\u4e2a <strong>V1 \u63a8\u8350\u65b9\u6848<\/strong>\uff1a<\/p>\n<h3>\u2705 Share Extension V1\uff08\u6781\u7b80\u4f46\u597d\u7528\uff09<\/h3>\n<ul>\n<li>\u65e0 UI\uff08\u76f4\u63a5\u5bfc\u5165\uff09<\/li>\n<li>\n<p>\u81ea\u52a8\u5224\u65ad\uff1a<\/p>\n<ul>\n<li>txt \u2192 \u76f4\u63a5\u6253\u5f00<\/li>\n<li>epub \u2192 \u89e3\u5305<\/li>\n<li>zip \u2192 \u89e3\u538b\u540e\u626b\u63cf<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5bfc\u5165\u5b8c\u6210\u540e\uff1a<\/p>\n<ul>\n<li>Toast\uff1a<code>\u5df2\u5bfc\u5165 3 \u672c\u7535\u5b50\u4e66<\/code><\/li>\n<li>\u81ea\u52a8\u8df3\u8f6c\u4e3b App<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u4e0d\u8981\u5728 Extension \u91cc\u505a\u9605\u8bfb \/ \u89e3\u6790 \/ \u89e3\u538b UI<\/strong><\/p>\n<hr \/>\n<h2>\u4e94\u3001\u771f\u5b9e\u5efa\u8bae\uff08\u6211\u4e0d\u7cd6\u8863\uff09<\/h2>\n<p>\u5982\u679c\u4f60\u662f\u505a <strong>\u5de5\u5177\u578b \/ \u4e2a\u4eba\u9605\u8bfb \/ \u6280\u672f\u6587\u6863<\/strong>\uff1a<\/p>\n<blockquote>\n<p><strong>Share Extension = \u6bd4\u201c\u767b\u5f55 \/ \u6ce8\u518c \/ \u4e91\u540c\u6b65\u201d\u91cd\u8981<\/strong><\/p>\n<\/blockquote>\n<p>\u6ca1\u6709\u5b83\uff1a<\/p>\n<ul>\n<li>\u7528\u6237\u6587\u4ef6\u8fdb\u4e0d\u6765<\/li>\n<li>\u83b7\u5ba2\u5168\u9760\u529d<\/li>\n<\/ul>\n<p>\u6709\u5b83\uff1a<\/p>\n<ul>\n<li>\u4e00\u6b21\u6210\u529f\u5bfc\u5165 = \u957f\u671f\u7559\u5b58<\/li>\n<\/ul>\n<hr \/>\n<h2>\u516d\u3001\u5982\u679c\u4f60\u613f\u610f\uff0c\u6211\u53ef\u4ee5\u7ee7\u7eed\u5e2e\u4f60\u505a\u7684\u51e0\u4ef6\u4e8b<\/h2>\n<p>\u4f60\u53ef\u4ee5\u76f4\u63a5\u9009 \ud83d\udc47<\/p>\n<p>1\ufe0f\u20e3 <strong>\u7ed9\u4f60\u4e00\u4efd\u300c\u7535\u5b50\u4e66 App + Share Extension\u300d\u5b8c\u6574 V1 \u529f\u80fd\u6811<\/strong><br \/>\n2\ufe0f\u20e3 <strong>\u5e2e\u4f60\u8bbe\u8ba1 Share Extension \u7684\u6700\u5c0f UX\uff08\u65e0 UI \/ \u6709 UI \u5bf9\u6bd4\uff09<\/strong><br \/>\n3\ufe0f\u20e3 <strong>\u5224\u65ad\u4f60\u73b0\u6709 App\uff0c\u5982\u4f55\u201c\u81ea\u7136\u5f15\u5165\u7535\u5b50\u4e66\u80fd\u529b\u201d\u800c\u4e0d\u91cd\u505a\u67b6\u6784<\/strong><br \/>\n4\ufe0f\u20e3 <strong>\u544a\u8bc9\u4f60\uff1a\u7535\u5b50\u4e66 vs \u89c6\u9891\u7c7b Share Extension\uff0c\u54ea\u6761\u66f4\u5bb9\u6613\u53d8\u73b0<\/strong><\/p>\n<p>\u4f60\u73b0\u5728\u8fd9\u4e00\u6b65\u95ee\u5f97\u5f88\u5bf9\uff0c\u8fd9\u662f<strong>\u771f\u4ea7\u54c1\u4eba<\/strong>\u624d\u4f1a\u5361\u7684\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u76f4\u63a5\u6309\u201c\u4f60\u8981\u771f\u505a\u4e00\u4e2a\u7535\u5b50\u4e66\u5de5\u5177\u578b App\u201d\u7684\u5b9e\u6218\u89c6\u89d2\u7ed9\u4f60\u8bb2\uff0c\u4e0d\u7ed5\u6982\u5ff5\u3002 \u4e00\u3001Share Extension &#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6956\">\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":[161],"tags":[],"class_list":["post-6956","post","type-post","status-publish","format-standard","hentry","category-161"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6956","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=6956"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6956\/revisions"}],"predecessor-version":[{"id":6957,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6956\/revisions\/6957"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}