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

查看:42
本文介绍了当应用程序在后台时,未在 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];
        });
    }
}];

payload 设置如下

The payload is set to the following

{"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天全站免登陆