菜鸟教程小白 发表于 2022-12-11 17:27:45

ios - 如何在 iOS 9 中从电子邮件 URL 打开应用程序?


                                            <p><p>我尝试过类似的方法:</p>

<p>在 AppDelegate 中:</p>

<pre><code>func application(application: UIApplication, handleOpenURL url: NSURL) -&gt; Bool {
    var returnValue = false
    let urlString = url.absoluteString
    print(urlString)
    if(urlString.hasPrefix(&#34;&#34;)){
      returnValue = true
    }
    return returnValue
}
</code></pre>

<p>在 info.plist 中</p>

<pre><code>&lt;key&gt;CFBundleURLTypes&lt;/key&gt;
&lt;array&gt;
    &lt;dict&gt;
      &lt;key&gt;CFBundleURLName&lt;/key&gt;
      &lt;string&gt;co.example.ExampleApp&lt;/string&gt;
      &lt;key&gt;CFBundleURLSchemes&lt;/key&gt;
      &lt;array&gt;
            &lt;string&gt;example&lt;/string&gt;
      &lt;/array&gt;
    &lt;/dict&gt;
&lt;/array&gt;
</code></pre>

<p>但不起作用。我希望通过我通过电子邮件发送的链接打开应用程序,有人有想法让它工作吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>对于 future 的用户,正如@iSashok 在评论中提到的,handleOpenURL 函数 <a href="https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622964-application" rel="noreferrer noopener nofollow">is deprecated as of iOS 9</a> . </p>

<p>对于较新版本的 iOS,您需要使用以下函数 (<a href="https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623112-application" rel="noreferrer noopener nofollow">Apple Docs</a>):</p>

<pre><code>optional func application(_ app: UIApplication,
               open url: URL,
            options: = [:]) -&gt; Bool
</code></pre>

<p>您将能够保持函数的主体与以前相同,现在它可以工作了。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 iOS 9 中从电子邮件 URL 打开应用程序?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39371601/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39371601/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 iOS 9 中从电子邮件 URL 打开应用程序?