且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xamarin Forms-Android-FCM-当应用程序处于前台,后台且滑动关闭状态时,会收到抬头通知

更新时间:2023-02-26 21:18:07

这可能是一个长镜头,但经过大量挖掘,我发现在后台,尤其是在被刷掉时,您无权访问XamarinForms对象因为只有在您实际完成start活动后,该实例才会被实例化.

This could be a long shot but after a lot of digging I found that when in background and especically when swiped away you don't have access to the XamarinForms object as it's only instantiated once you actually go through the start activity.

例如如果这实际上是使用DependencyService或另一个Forms库,则将收到错误.

E.g. if this is actually using a DependencyService or another Forms library you will get an error.

CrossBadge.Current.SetBadge(_notificationBadgeCount)

还要确保从通知服务器将默认优先级设置为 high ,这是默认设置,这是正常的,如果将其清除,不会导致应用程序唤醒.

also make sure from your notification server you are setting the priority to high it is normal by default which will not cause the WAKEUP of the app if swiped away.

priority: "high",

android: {
    priority: "high",
    notification: {
        title: title,
        body: body,
        sound: "default",
        priority: "high",
        sticky: false,
        defaultSound: true,
        defaultVibrateTimings: true,
    },
    data: {        
       title: title,
       body: body
   }
}