菜鸟教程小白 发表于 2022-12-11 20:06:31

ios - 使用在后台运行的应用程序打开文件


                                            <p><p>我正在创建一个应用程序,当我在该文件的<strong>“打开方式”</strong>对话框中点击我的应用程序图标时,该应用程序应该能够打开该文件。为了做到这一点,我假设我可以通过 <code>AppDelegate</code> 中的 <code>application(_:didFinishLaunchingWithOptions:) 或 application(_:willFinishLaunchingWithOptions:)</code> 获取文件数据,从那里我可以获取外部文件的 url。应用启动时。</p>

<p>但是,当我在文件的<strong>“打开方式”</strong>对话框中点击其图标时,我的应用程序应该已经在后台运行。因此, <code>application(_:didFinishLaunchingWithOptions:) 或 application(_:willFinishLaunchingWithOptions:)</code> 永远不会被调用,因为在这种情况下应用程序将从后台返回,因此只有函数 <code>applicationWillEnterForeground(_ :)</code> 在 <code>AppDelegate</code> 被调用。</p>

<p>有什么想法可以解决这个问题吗? (对不起我的英语不好)</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>查看 <code>application(_:open:options:)</code>。当您的应用程序已经运行而不是 <code>application(_:didFinishLaunchingWithOptions:)</code> 当另一个应用程序想要打开您的应用程序时,会调用此方法。</p>

<p>在此处查看 Apple 的文档:<a href="https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application" rel="noreferrer noopener nofollow">https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 使用在后台运行的应用程序打开文件,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/50125507/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/50125507/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 使用在后台运行的应用程序打开文件