简体   繁体   English

使用Xamarin表单为Android和iOS设置推送通知徽章时遇到问题

[英]Trouble setting push notification badge for Android and iOS using Xamarin Forms

I'm having trouble with the icon badge using push notifications on my Xamarin Forms app. 我在Xamarin Forms应用程序上使用推送通知在使用图标徽章时遇到了麻烦。 I'm using Firebase to send the app to both devices. 我正在使用Firebase将应用程序发送到两个设备。

The way I had the badge working for android was that the app gets the complete notification info from the payload's 'data' section. 我为Android使用徽章的方式是,该应用从有效负载的“数据”部分获取了完整的通知信息。 When the notification only has a data section I can trigger a function that will set the badge and show the popup notification. 当通知仅包含数据部分时,我可以触发一个功能,该功能将设置徽章并显示弹出通知。 If I put the same info in the 'notification' section I can't cause a trigger to set the badge. 如果我在“通知”部分中输入了相同的信息,则无法触发设置徽章的触发器。

For iOS, the badge count gets sent from the payload's 'notification' section. 对于iOS,徽章计数是从有效内容的“通知”部分发送的。 iOS doesn't see the 'data' section and create an automatic popup. iOS没有看到“数据”部分并创建自动弹出窗口。 I've tried triggering a function when the app is in the background but couldn't find a way. 我尝试过在应用程序处于后台但无法找到方法时触发功能。

Bottom line: iOS needs the 'notification' payload and Android needs the 'data' payload to show the proper badge. 底线:iOS需要“通知”有效负载,而Android需要“数据”有效负载以显示正确的标志。

Does anyone know how I can trigger a function in my AppDelegate on iOS when the app is in the background and a push notification is received and/or does anyone know how to trigger a function in Android when there is a 'notification' section in the payload? 有没有人知道当应用程序在后台并且收到推送通知时,如何在iOS的AppDelegate中触发功能,和/或没有人知道如何在Android的“通知”部分中触发功能。有效载荷?

This is my payload: 这是我的有效载荷:

{
    "to":"{mytoken}",
    "notification":{
        "title":"Appointment Almost Booked",
        "body":"Please confirm your appointment",
        "badge":3
    },
    "data":{
        "title":"Appointment Almost Booked",
        "body":"Please confirm your appointment slot",
        "badge":3
    }
}

For iOS: 对于iOS:

You can refer to: 您可以参考:

https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support . https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

In table 1,there is a property content_available you can set to awake your application when your application is in background. 在表1中,有一个属性content_available您可以将其设置为在后台运行应用程序时将其唤醒。

On iOS, use this field to represent content-available in the APNs payload. 在iOS上,使用此字段表示APNs有效内容中可用的内容。 When a notification or message is sent and this is set to true, an inactive client app is awoken, and the message is sent through APNs as a silent notification and not through the FCM connection server. 发送通知或消息并将其设置为true时,将唤醒不活动的客户端应用程序,并且消息通过APN作为静默通知而不是通过FCM连接服务器发送。 Note that silent notifications in APNs are not guaranteed to be delivered, and can depend on factors such as the user turning on Low Power Mode, force quitting the app, etc. On Android, data messages wake the app by default. 请注意,APN中的无提示通知不能保证会传递,并且可能取决于诸如用户打开低功耗模式,强制退出应用程序等因素。在Android上,默认情况下,数据消息会唤醒应用程序。 On Chrome, currently not supported. 在Chrome上,目前不支持。

Then you can trigger your function in DidReceiveRemoteNotification . 然后,您可以在DidReceiveRemoteNotification触发函数。

And here is a link that might help you: 这是一个可能对您有帮助的链接:

https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push#configure-and-run-the-ios-project-optional https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push#configure-and-run-the-ios-project-可选的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin 表单:推送通知不适用于 Android 7.1.2 - Xamarin forms: Push notification is not working on Android 7.1.2 PutExtra值没有通过使用xamarin表单和android的推送通知传递给mainactivity - PutExtra Value not being passed to mainactivity from push notification using xamarin forms and android 如何在Xamarin.Forms Android中将通知推送给特定用户? - How to push notification to specific users in Xamarin.Forms Android? Xamarin.Forms Android推送通知不会出现 - Xamarin.Forms Android Push Notification Doesn't Appear 来自 xamarin.forms 的 Android 推送通知按钮单击挂起 - Android push notification from xamarin.forms button click hangs Android 在主屏幕上推送通知徽章计数器 - Android push notification badge counter on Home Screen 在具有Firebase的Android推送通知中设置徽章计数? - Set Badge Count in Android Push Notification with Firebase? 使用 ReactNative 为 Android 和 iOS 推送通知 - Push Notification for Android and iOS using ReactNative 自定义 Firebase 推送通知未显示 Android 通知徽章点 - Android notification badge dot not showing for custom firebase push notification 推送通知徽章不消失 - Push notification badge not disappearing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM