菜鸟教程小白 发表于 2022-12-11 17:04:28

ios - 无法连接到 URL ms-word URL 方案


                                            <p><p>我正在将用户发送到 Microsoft Word 应用程序以编辑文档。为此,我使用了一个在我的 <code>info.plist</code> 中作为“ms-word”列入白名单的 URL 方案。我读过的所有问题和答案都是我尝试过多次的<code>outdated/involve</code>解决方案。</p>

<p>在您说“只使用 <code>UIDocumentInteractionController</code>”之前,该文档 Controller 不允许编辑同一个文件,并且在查看文档后它无法将用户发送回原始应用程序。</p >

<p>这是我在 Objective-C 中尝试过的内容</p>

<pre><code>NSURL *ourURL = ];
if([ canOpenURL:ourURL] ) {
    [ openURL:ourURL];
}
</code></pre>

<p>我也尝试过这种变体,例如删除编码并将管道手动编码为 %7C,因为这是编码后的最终结果。我看到的教程中使用了这种变体 <a href="https://blog.beecomedigital.com/2015/02/16/opening-a-document-with-office-mobile-from-your-own-application/" rel="noreferrer noopener nofollow">here</a> . </p>

<p>这是另一个 <a href="http://wopi.readthedocs.io/projects/officewopi/en/latest/scenarios/from_app.html" rel="noreferrer noopener nofollow">tutorial</a>我看着那对我不起作用。</p>

<p>我还尝试了通过文件类型 <code>.doc/.docx</code> 在 google 上找到的其他面向公众的 word 文档,但没有任何效果。</p>

<p>这是我在 Swift 中尝试过的内容</p>

<pre><code>let ourURL = NSURL(string: (&#34;ms-word:ofe|u|http://www.fcu.edu.tw/wSite/public/Attachment/f1355389313906.doc&#34;).stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!)!
      print(ourURL)
      let ourApplication:UIApplication = UIApplication.sharedApplication()
      if(ourApplication.canOpenURL(ourURL)) {
            ourApplication.openURL(ourURL)
      }
</code></pre>

<p>我再次尝试了多种变体、不同的编码、<code>NSUTF8、stringByAddingPercentEscapesUsingAllowedCharacters(NSCharacters.URLQueryAllowedCharacterSet())</code>,以及不同的 word 文档 url...</p>

<p>我也尝试过下载文档的 <code>NSData</code> 并将其本地写入手机中的文件目录,然后打开该文件,但 <code>URL</code> 方案没有支持本地目录(<code>UIDocumentInteractionController</code> 确实支持这一点,但同样,您不能编辑该副本,也不能将用户返回到他们的应用程序)。</p>

<p>有<a href="https://msdn.microsoft.com/en-us/library/office/dn911482.aspx#sectionSection1" rel="noreferrer noopener nofollow">little documentation</a>关于 ms word 的 url 方案,我已经对该主题进行了大量研究,似乎还有很多人仍然遇到同样的问题,并且已经去了 <a href="http://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365legacy-mso_mobaccess/ios-how-to-open-word-app-via-uri-scheme-with-a/c061f306-6062-4571-9561-114987c4f352" rel="noreferrer noopener nofollow">Microsoft forums</a>以及其他没有解决方案的帮助论坛,因为这些论坛的成员在该特定领域没有经验。</p>

<p>每次尝试都会导致:</p>

<p>1) Word 成功启动,但随后我收到此错误:“无法连接到 <code>URL</code>,请使用有效的 <code>URL</code>”</p>

<p>2) Word 成功启动,但随后我收到相同的错误,然后在消除错误后我看到类似“word 无法在 url 打开文件”</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我了解到我不断收到此错误,因为它只是<strong>不可能</strong>。</p>

<p>要使 ms-word url 方案起作用,文档必须位于 SharePoint 或 OneDrive 中,声明为 <a href="https://msdn.microsoft.com/en-us/library/office/dn911482.aspx#sectionSection1" rel="noreferrer noopener nofollow">here</a> .</p>

<blockquote>
<p>You can enable users who are running Office on an iOS device to open and edit <strong>files stored in SharePoint or OneDrive</strong> from any application, and then quickly return them to the original application when they’re done editing the file.</p>
</blockquote></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 无法连接到 URL ms-word URL 方案,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38528983/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38528983/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 无法连接到 URL ms-word URL 方案