[英]`pushDisallowed` and `Decision: Absolutely Must Not Proceed` on iPhone after some testing/debugging with background pushes
I am creating a Xamarin Forms app which is using background pushes via Azure Notification Hub.我正在创建一个 Xamarin Forms 应用程序,它通过 Azure 通知中心使用后台推送。 The app is targeting Android and iOS and after some initial prototyping and testing everything worked fine on both platforms.
该应用程序的目标是 Android 和 iOS,经过一些初始原型设计和测试后,在两个平台上一切正常。 For iOS I am sending pushes with the following content:
对于 iOS,我正在发送包含以下内容的推送:
{ "aps": { "content-available": 1, "apns-priority": 5, "sound": "", "badge": 0 }, "id": 10, "title": "PushDemo", "message": "Hello #10!" }
In my AppDelegate
the DidReceiveRemoteNotification
method did get called no matter if the app was active, in the background or completely closed.在我的
AppDelegate
中,无论应用程序是处于活动状态、在后台还是完全关闭,都会调用DidReceiveRemoteNotification
方法。 I then create a visible notification manually via code and show it to the user (and because I also need to execute some other logic I do not use "alert" directly in the push).然后我通过代码手动创建一个可见通知并将其显示给用户(并且因为我还需要执行一些其他逻辑我不直接在推送中使用“警报”)。
I then started implementing all the platform-specific logic in the Android project and there I did send a bunch of test-notifications via my backend-service where also my iPhone was still registered from the prototying phase.然后我开始在 Android 项目中实现所有特定于平台的逻辑,并且我确实通过我的后端服务发送了一堆测试通知,我的 iPhone 仍然从原型阶段注册。 So I saw my iPhone also receiving all the test-pushes while I was testing the Android app.
所以我在测试 Android 应用程序时看到我的 iPhone 也收到了所有测试推送。 After finishing the Android side I got back to iOS and also implemented everything there, still working as expected.
完成 Android 端后,我回到 iOS 并在那里实现所有内容,仍然按预期工作。 But soon after that the iPhone stopped receiving my pushes.
但不久之后,iPhone 就停止接收我的推送。
After investigating I found out that the DidReceiveRemoteNotification
is not called anymore, no matter the state of the app, only the WillPresentNotification
in my UNUserNotificationCenterDelegate
is called if the app is active in the foreground.经过调查,我发现不再调用
DidReceiveRemoteNotification
,无论应用程序的 state,如果应用程序在前台处于活动状态,则只调用我的WillPresentNotification
中的UNUserNotificationCenterDelegate
。
After some more investigation (and verifying my test-app using the same code is still working completely) I saw that everything is working (eg badge number update) also in the background except calling my handler in code.经过更多调查(并使用相同的代码验证我的测试应用程序仍在完全运行)后,我看到除了在代码中调用我的处理程序之外,一切都在后台运行(例如徽章编号更新)。
I then dug through the device logs and found the following after a push is received:然后我通过设备日志挖掘并在收到推送后发现以下内容:
dasd[93]: com.apple.pushLaunch.com.Company.MyApp:AB795D:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} ], FinalDecision: Absolutely Must Not Proceed}
dasd[93]: com.apple.pushLaunch.com.Company.MyApp:AB795D:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed] :必需:0.00,观察到:1.00},]}} ],FinalDecision:绝对不能继续}
(BTW: I had to use the Mac to get that, the device log in VS did not show the part after the [
) (顺便说一句:我不得不使用 Mac 来获取它,VS 中的设备日志没有显示
[
之后的部分)
I guess the power saver of my iPhone deemed my app to pollute my phone as a lot of notifications where received and not interacted with.我猜我的 iPhone 的节电器认为我的应用程序污染了我的手机,因为收到了很多通知但没有与之交互。
How can I tell my iPhone to allow those notifications again?我怎样才能让我的 iPhone 再次允许这些通知?
I had a similar problem and solved it by removing the sound key, ie "sound": ""
, from the content to be sent.我遇到了类似的问题,通过从要发送的内容中删除声音键(即
"sound": ""
)解决了这个问题。 If you look into the docs for "content-available": 1
:如果您查看“可用内容”的文档
"content-available": 1
:
The background notification flag.
后台通知标志。 To perform a silent background update, specify the value 1 and don't include the alert, badge, or sound keys in your payload.
要执行静默后台更新,请指定值 1 并且不要在您的负载中包含警报、徽章或声音键。 See Pushing Background Updates to Your App.
请参阅将后台更新推送到您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.