我在敲我的头。我正在实施推送通知。一切正常(收到推送,更新徽章),但在 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];
});
}
}];
Run Code Online (Sandbox Code Playgroud)
有效载荷设置为以下
{"aps": {
"badge": 10,
"alert": "test",
"content-available": 1
}}
Run Code Online (Sandbox Code Playgroud)
我尝试在所有变体中添加“远程通知”和“后台处理”作为应用程序功能(仅“远程通知”/“后台处理”,没有任何这些功能,启用两者)而没有任何更改。我为 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 …Run Code Online (Sandbox Code Playgroud) objective-c apple-push-notifications ios silent-notification ios13