当应用程序在后台运行时,iOS 13.3中未调用didReceiveRemoteNotification [英] didReceiveRemoteNotification not called in iOS 13.3 when app is in background

查看:95
本文介绍了当应用程序在后台运行时,iOS 13.3中未调用didReceiveRemoteNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在敲头.我正在实施推送通知.一切正常(接收到推送,更新了徽章),但是在iOS 13.3下,当应用程序在后台运行时,不会调用application(_:didReceiveRemoteNotification:fetchCompletionHandler :)方法.如果应用程序在前台或使用iOS 12设备,则将调用该方法.我通过以下方式注册推送通知:

I am banging my head. I am implementing push notification. Everything is working fine (push is received, badge is updated) but under iOS 13.3 the method application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is not called when the app is in the background. If the app is in the foreground or using an iOS 12 device the method is called. I register for push notification in the following way:

[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
    if (granted) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        });
    }
}];

有效负载设置为以下

{"aps": {
    "badge": 10,
    "alert": "test",
    "content-available": 1
}}

我尝试在所有变体中添加远程通知"和背景处理"作为应用程序功能(仅远程通知"/背景处理",而没有其中的任何一项功能,同时启用了这两项),而没有进行任何更改.我为UNUserNotificationCenter设置了委托,但是再次失败了.我相应地设置了标题:

I tried adding "Remote notifications" and "Background processing" as app capabilities in all variations (only "Remote notifications"/"Background processing", without any of those capabilities, enabling both) without any change. I set the delegate for the UNUserNotificationCenter but again without success. I set the headers accordingly:

curl -v \
 -H 'apns-priority: 4' \
 -H 'apns-topic: xx.xxxxx.xxxx' \
 -H 'apns-push-type: alert' \
 -H 'Content-Type: application/json; charset=utf-8' \
 -d '{"aps": {"badge": 10,"alert": "test", "content-available":1}}' \
 --http2 \
 --cert pushcert.pem \
 https://api.sandbox.push.apple.com/3/device/1234567890

从文档中可以看出,即使应用程序在后台运行,该方法也会被调用:

From the docs it states that this method is called even when the app is in background:

使用此方法为您的应用处理传入的远程通知.与application:didReceiveRemoteNotification:方法不同,该方法是仅当您的应用在前台运行时才调用当您的应用程序在前台运行时调用此方法,或者背景.

Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background.

对于iOS 13,我在这里缺少什么?

What am I missing here for iOS 13?

推荐答案

您已设置

"content-available": 1

您的后端APS有效载荷是什么?

in you backend APS payload?

还需要确保您已在iOS应用的info.plist文件中启用了后台模式

Also need to make sure you have enabled background mode in your iOS App's info.plist file

<key>UIBackgroundModes</key>
<array>
    <string>processing</string>
    <string>remote-notification</string>
</array>

这篇关于当应用程序在后台运行时,iOS 13.3中未调用didReceiveRemoteNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆