如何解决Xamarin表格应用程式在关闭应用程式后1天后仍未收到FCM通知
我有xamarin表单应用程序,该应用程序具有使用Firebase FCM应用程序从.net核心后端发送的通知,在应用程序的前台和后台以及应用程序关闭的头几个小时内,它们会收到很好的通知,但是如果我不打开该应用程序,则会出现问题有一天,然后发送通知,直到我打开应用程序然后通知到达,应用程序才收到通知(注意:当应用程序打开时,不更新Firebase设备令牌) 我在Android中使用PushNotificationPlugin处理通知和这种情况。
清单代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.2" package="com.QuranMajead.android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="QuranMajead" android:usesCleartextTraffic="true" android:icon="@drawable/ic_launcher">
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
主应用程序类
[Application]
public class MainApplication : Application
{
public MainApplication(IntPtr handle,JniHandleOwnership transer) : base(handle,transer)
{
}
public override void OnCreate()
{
base.OnCreate();
//Set the default notification channel for your app when running Android Oreo
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
//Change for your default notification channel id here
Pushnotificationmanager.DefaultNotificationChannelId = "QuranMajeadChannel";
//Change for your default notification channel name here
Pushnotificationmanager.DefaultNotificationChannelName = "QuranMajeadChannelName";
}
//If debug you should reset the token each time.
#if DEBUG
Pushnotificationmanager.Initialize(this,true);
#else
Pushnotificationmanager.Initialize(this,false);
#endif
var data = Intent.ExtraIntent;
//Handle notification when app is closed here
CrosspushNotification.Current.OnNotificationReceived += (s,p) =>
{
};
CrosspushNotification.Current.OnTokenRefresh += (s,p) =>
{
Preferences.Set("Devicetoken",p.Token);
};
CrosspushNotification.Current.OnNotificationopened += (s,p) =>
{
System.Diagnostics.Debug.WriteLine($"Opened Notification : {p.Data}");
};
}
}
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。