ios - 应用程序处于后台时,iOS 13.3 中未调用 didReceiveRemoteNotification

标签 ios objective-c apple-push-notifications ios13 silent-notification

我在敲我的头。我正在实现推送通知。一切正常(收到推送,更新角标(Badge)),但在 iOS 13.3 下,应用程序在后台时不会调用方法 application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 。如果应用程序在前台或使用 iOS 12 设备,则调用该方法。我通过以下方式注册推送通知:

[[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 设置了委托(delegate),但再次没有成功。我相应地设置了标题:
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

从文档中可以看出,即使应用程序处于后台,也会调用此方法:

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 我在这里缺少什么?

最佳答案

你设置了吗

"content-available": 1

在您的后端 APS 有效负载中?

还需要确保您在 iOS 应用程序的 info.plist 文件中启用了后台模式
<key>UIBackgroundModes</key>
<array>
    <string>processing</string>
    <string>remote-notification</string>
</array>

关于ios - 应用程序处于后台时,iOS 13.3 中未调用 didReceiveRemoteNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59876964/

相关文章:

ios - UITableViewCell 堆积起来,反复出现

iphone - 如何在 UITableView 中激活下一个 UITextField?

ios - 我怎样才能把角标(Badge)图标放在菜单栏的应用程序中?

ios - OneSignal 不调用 didReceiveRemoteNotification

objective-c - EXC_BAD_ACCESS 错误使用 ALAssetsLibrary assetForURL :resultBlock:failureBlock:

ios - 如何快速提高 AV 录制质量。我要高清录像

objective-c - UIImageJPEGRepresentation 给出 EXC_BAD_ACCESS

ios - 关闭应用程序时从推送通知显示 ViewController 的正确方法

ios - setStatusBarStyle :animated: deprecated

iphone - 检查以编程方式生成的 ImageView 的相交