菜鸟教程小白 发表于 2022-12-11 20:28:48

IOS - 通过单击 UNNotificationAction 处理后的丰富推送重复


                                            <p><p>富推送在后台处理后(用户在未打开应用的情况下点击了UNNotificationAction - 无前台)),然后当您进入应用时,会出现重复推送事件导致“didReceiveRemoteNotification”执行。</p>

<p><strong>我的问题是:</strong></p>

<p>为什么当我处理富人插入时:</p>

<pre><code>func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {
</code></pre>

<p>并调用competitionHandler(),收到相同的推送:</p>

<pre><code>func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: , fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void)
</code></pre>

<p>?</p>

<p><strong>推送设置:</strong></p>

<pre><code>UNUserNotificationCenter.current().delegate = self

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
                if granted {
                  print(&#34;UNUserNotificationCenter auth granted&#34;)
                  Utils.performTaskOnMain {
                        application.registerForRemoteNotifications()
                  }
                } else {
                  print(&#34;UNUserNotificationCenter auth error = \(error?.localizedDescription ?? &#34;&#34;)&#34;)

                }
</code></pre>

<p><strong>推送处理程序</strong></p>

<pre><code>func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: , fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void)
    {
      print(&#34;AppDelegate didReceiveRemoteNotification, with info:\(userInfo)&#34;)
      handleNotificationUserInfo(userInfo)
      completionHandler(UIBackgroundFetchResult.newData)
    }


    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {
               UserNotificationsManager.shared.handleActionIdentifierForReceivedNotification(response)
         completionHandler()
    }
</code></pre>

<p><strong>推送通知负载:</strong></p>

<pre><code>info:[AnyHashable(&#34;content-available&#34;): 1, AnyHashable(&#34;messageInfo&#34;): {&#34;push_type&#34;:&#34;XXXX&#34;,&#34;category&#34;:&#34;videoCategory&#34;,&#34;mediaUrl&#34;:&#34;https://XXXX.png&#34;,&#34;threadId&#34;:&#34;24274&#34;,&#34;alertTitle&#34;:null,&#34;initiator&#34;:&#34;XXXXX XXXX.mp3&#34;,&#34;alertBody&#34;:null,&#34;mutableContent&#34;:true}, AnyHashable(&#34;media-url&#34;): https://XXXXX.png, AnyHashable(&#34;aps&#34;): {
alert =   {
    body = &#34;XXXXX&#34;;
};
badge = 56;
category = &#34;XXX.videoCategory&#34;;
&#34;content-available&#34; = 1;
&#34;mutable-content&#34; = 1;
sound = &#34;XXXX.mp3&#34;;
</code></pre>

<p>}]</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>传送到您的应用程序的“重复”推送是静默推送通知。除了 <code>alert</code> 字典之外,您的推送通知还包含 <code>content-available</code> 键。</p>

<p><code>alert</code> 字典会导致发送用户可见的通知。</p>

<p><code>content-available</code> 键会导致它作为静默推送通知再次传递,用户看不到。</p>

<p>这是不受支持的配置。移除 <code>content-available</code> 键,只会发送用户可见的推送通知。如果您正在积极使用静默推送,请将其作为单独的推送发送,其中仅包含 <code>content-available</code>、<code>category</code> 和您的自定义键。</p></p>
                                   
                                                <p style="font-size: 20px;">关于IOS - 通过单击 UNNotificationAction 处理后的丰富推送重复,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/51929483/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/51929483/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: IOS - 通过单击 UNNotificationAction 处理后的丰富推送重复