【发布时间】:2020-05-09 15:08:44
【问题描述】:
我在敲我的头。我正在实施推送通知。一切正常(收到推送,更新徽章),但在 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];
});
}
}];
payload设置如下
{"aps": {
"badge": 10,
"alert": "test",
"content-available": 1
}}
我尝试在所有变体中添加“远程通知”和“后台处理”作为应用程序功能(仅“远程通知”/“后台处理”,没有任何这些功能,同时启用两者),没有任何更改。我为 UNUserNotificationCenter 设置了委托,但再次没有成功。我相应地设置了标题:
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
从文档中可以看出,即使应用程序处于后台,也会调用此方法:
使用此方法为您的应用处理传入的远程通知。 与 application:didReceiveRemoteNotification: 方法不同,它是 仅当您的应用程序在前台运行时调用,系统 当您的应用在前台运行时调用此方法或 背景。
对于 iOS 13,我在这里缺少什么?
【问题讨论】:
-
请参见上文:一切正常(收到推送,更新徽章)但在 iOS 13.3 下,当应用程序在后台时,不会调用方法 application(_:didReceiveRemoteNotification:fetchCompletionHandler:) .
-
application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 将在您点击通知横幅时被调用
-
是的,这是正确的。我的问题是:为什么应用程序在后台时不调用它。据我了解,文档是这样说的。
-
您是否尝试过实现
application(_:didReceiveRemoteNotification:withCompletionHandler:)方法?
标签: ios objective-c apple-push-notifications ios13 silent-notification