菜鸟教程小白 发表于 2022-12-12 13:40:22

iOS - 在收到推送通知事件时更改 View 的内容


                                            <p><p>我来自 Android 开发背景。在 Android 中,您发送一个推送通知,然后您使用服务处理其余的事情(创建实际的系统通知、修改应用程序的内容等)。</p>

<p>据我所知,在发送 iOS 推送通知时,它会根据您的消息负载在通知中心自动为您创建系统通知。在这里和谷歌上搜索后,我想我必须使用 application:didReceiveRemoteNotification 事件来添加/删除 View 的内容。如何访问推送通知的内容,以便我也可以将其放入应用程序中(即使用户在通知中心关闭了通知,我也想在应用程序中显示消息)?稍后(通常是同一天)会有另一条消息从应用程序中删除。</p>

<p>我知道如果应用程序关闭,将不会调用 application:didReceiveRemoteNotification 方法,因此我将不得不使用其他一些事件(如 didfinishlaunching)来获取消息。但是如何访问推送通知的消息本身呢?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><blockquote>
<p>I want to display the message in the app even if the user has dismissed the notification in the notification center</p>
</blockquote>

<p>这是不可能的。仅当用户从通知中心打开应用程序时,iOS 才会将通知数据传递给您的应用程序。如果用户关闭通知并稍后启动应用程序,则应用程序获取此数据的唯一方法是从您的服务器检索。</p>

<p>应用从通知中心启动时获取通知数据见<a href="https://stackoverflow.com/questions/14968578/calling-didreceiveremotenotification-when-app-is-launching-for-the-first-time/" rel="noreferrer noopener nofollow">this question</a> .</p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS - 在收到推送通知事件时更改 View 的内容,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18364559/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18364559/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS - 在收到推送通知事件时更改 View 的内容