尝试将推送通知添加到我的 Xamarin.Forms 应用程序,但找不到任何实施 Firebase 云消息传递的工作示例。 我的意思是,所有示例/教程中都没有一个可行的示例。 请您指点我一下好吗?
您可以先查看文档Firebase Cloud Messaging。本文概述了 FCM 的工作原理,并说明了如何配置 Google 服务,以便您的应用可以使用 FCM。
xamarin android中的实现过程与xamarin forms类似。
您还可以在浏览器中找到更多教程。
它在 Android 版本中适用于我,如果您使用新的 Firebase 云消息传递(HTTP v1),您应该将 Xamarin.Firebase.Messaging 更新到最新版本(在我的工作中我使用 123.3.1.1)并执行以下步骤
添加 google-services.json 不要忘记设置构建操作 GoogleServiceJson
在AndroidMenifest中添加Internet权限和PostNotification权限
新文件 FirebaseMessageing 仅因为 Xamarin.Firebase.Messaging 较新版本 121.0.1 不使用 FirebaseInstanceIdService
公共类FirebaseMessageing:FirebaseMessagingService { const string TAG = "FirebaseMessageing";
public override void OnNewToken(string token)
{
base.OnNewToken(token);
Log.Debug(TAG, "Update Token: " + token);
Preferences.Set("TokenFirebase", token);
}
public override void OnMessageReceived(RemoteMessage message)
{
Log.Debug(TAG, "From: " + message.From);
Log.Debug(TAG, "Toppic: " + message.GetNotification().Title);
Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
}
}
如果我理解有误,请告诉我。