菜鸟教程小白 发表于 2022-12-12 08:53:56

ios - 通过从应用程序图标启动来处理应用程序完全关闭时的远程通知


                                            <p><p>我可能会与风车搏斗,但我需要了解一下我对<strong>远程通知</strong>的了解。我想在我的应用程序关闭时处理通知(从应用程序切换器中杀死),但用户决定不是通过点击通知而是通过点击应用程序图标来打开它。</p>

<p>据我所知,当应用程序被杀死并且远程通知到达时,用户必须点击通知以在 <code>didFinishLaunchingWithOptions:</code> 的 <code>launchOptions</code> 中传递它,但是......当用户点击应用程序图标并且没有任何内容传递给 <code>lauchOptions</code> 时,我想处理此通知。在那种情况下,目前我根本没有任何通知......</p>

<p><strong>无论应用程序如何启动,是否可以在后台处理通知并对其执行操作?</strong>也许 <code>didReceiveRemoteNotification: fetchCompletionHandler:</code>?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>是的,你在和风车搏斗:)</p>

<p>我建议您阅读 <a href="https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html" rel="noreferrer noopener nofollow">Local and Push Notifications in depth</a> .有点长,但是文档很清楚。</p>

<p>在此文档的片段中,您可以阅读:</p>

<blockquote>
<p>If the application icon is tapped on a device running iOS, the
application calls the same method
(application:didFinishLaunchingWithOptions:), but furnishes no
information about the notification.</p>
</blockquote>

<p>后来:</p>

<blockquote>
<p>When handling remote notifications in
application:didFinishLaunchingWithOptions: or
applicationDidFinishLaunching:, the application delegate might perform
a major additional task. Just after the application launches, the
delegate should connect with its provider and fetch the waiting data.
Listing 2-5 gives a schematic illustration of this procedure.</p>
</blockquote>

<p>话虽如此,您可以为服务器中的每台设备提供已发送通知的列表,并且每次启动应用时检查设备是否有任何待处理的通知。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 通过从应用程序图标启动来处理应用程序完全关闭时的远程通知,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/22620952/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/22620952/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 通过从应用程序图标启动来处理应用程序完全关闭时的远程通知