菜鸟教程小白 发表于 2022-12-11 17:07:39

ios - Firebase SDK 未提供后台通知


                                            <p><p>我正在尝试使用 Firebase 向我的应用发送后台推送通知。 iOS 可以正常显示通知,但我的 <code>AppDelegate</code> 上没有调用 <code>-application:didReceiveRemoteNotification:fetchCompletionHandler:</code>。</p>

<p>当设备连接到调试器时,当设备收到通知时,我会收到以下日志消息。</p>

<blockquote>
<p>2016-07-27 15:13:08.234:FIRMessaging receiving notification in invalid state 2</p>

<p>2016-07-27 15:13:08.234 MyApp Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.</p>
</blockquote>

<p>在我看来,Firebase 正在调整 <code>-application:didReceiveRemoteNotification:fetchCompletionHandler:</code> 但未能调用我的实现,因为它认为应用程序处于无效状态,但事实并非如此。</code> p>

<p>通知负载也没有什么特别之处,会导致问题。</p>

<pre><code>{
    gcm.message_id: 0:1469652824137045%3aef914a3aef914a,
    objectId: 7,
    aps: {
      alert: &#34;Your object has been updated&#34;
      content-available: 1
    }
}
</code></pre>

<p><strong>为什么 Firebase 说应用处于无效状态并且无法将通知转发到我的 <code>AppDelegate</code>?</strong></p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我认为您可能误解了该错误 - 发生此错误是因为您的应用的 <code>didReceiveRemoteNotification</code> 处理程序 <strong>正在</strong> 被调用。</p>

<p>问题可能是在您的 <code>didReceiveRemoteNotification</code> 处理程序中,您需要确保使用正确的 <code>UIBackgroundFetchResult</code> 类型调用 <code>completionHandler</code>。 (如果你使用 Swift,它可能看起来像 <code>completionHandler(.NewData)</code>。)</p>

<p>这基本上是您的应用在向其发送远程通知时让 iOS 知道它已完成您希望它执行的任何工作的方式。如果您不这样做,iOS 将会对您的应用不满意,并可能在未来停止向其转发通知。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Firebase SDK 未提供后台通知,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38623433/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38623433/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Firebase SDK 未提供后台通知