使用Microsoft.AppCenter以Xamarin形式推送通知

问题描述 投票:1回答:1

问:我在Microsoft.AppCenter中使用XAMARIN表单。如何使用AppCenter API获取Firebase设备ID,以便从后端向我的移动客户端(Android / IOS)发送推送通知?

前端(要求)1. XAMARIN表格2. Microsoft.AppCenter3. Microsoft.AppCenter.Push4.必须使用AppCenter获取FireBase设备ID。5. AppCenter.GetInstallIdAsync()对我的后端不起作用。我需要FireBaseDeviceID6.

后端(要求)1.我必须使用FireBase的https://fcm.googleapis.com/fcm/send POST请求拨打电话。

我有一个后端服务器,需要将推送直接发送到firebase。并非通过AppCenter。我要发送到的每个设备都需要firebase的DeviceID。我可以将其推送到应用程序的所有设备。但是我还需要转到通过AppCenter注册的特定设备。这就是为什么我需要前端应用程序来获取PUSH的FireBase DeviceID的原因。

xamarin.forms push-notification firebase-cloud-messaging deviceid
1个回答
0
投票

您无法通过使用AppCenter获取Firebase ID。您有两种解决方法:1.使用AppCenter跳过应用程序中的推送。您必须根据文档在与您支持的每个平台上实现与Firebase的交互。如果您选择此选项,我可以分享更多提示。2.说服后端团队使用AppCenter API发送单独的推送通知https://openapi.appcenter.ms/#/push/Push_Send我知道每种解决方案都与您的要求相抵触。但是您只需要为您的项目选择一种推送服务(AppCenter或Firebase)并坚持使用即可。我个人投票支持Firebase,是通过艰难的方式学习的。

更新

大多数时候,切换到FCM时,Firebase documentation是您最好的朋友。

在应用程序一侧:

设置Firebase客户端for iOSfor Android

根据我的经验得出的一些技巧:

Android:您必须在FirebaseMessagingService的后代中侦听Firebase InstanceID的更改,并将其存储以备后用。无论何时需要,AppCenter都不可用。

我的活动有LaunchMode = LaunchMode.SingleTop,并且我根据应用程序到达时的状态重写了两种处理推入的方法:void OnNewIntent(Intent intent)void OnPostCreate(Bundle savedInstanceState)。可能不是您的情况,因为我也处理无声推送。要检查意图是否包含来自Firebase的推送,请运行intent?.GetStringExtra("google.message_id") != null

iOS:推送通知在iOS模拟器上不起作用,并且在Simulator上运行时,初始化步骤可能会使您的应用程序崩溃。我在csproj文件的__IOS_SIMULATOR__配置下的__IOS__DEBUG旁边创建了Debug|iPhoneSimulator常量。像这样在AppDelegate.cs中使用它:

#if !__IOS_SIMULATOR__
    new FirebaseCloudMessagingInitializer().Init();
#endif

[同样是https://github.com/firebase/firebase-ios-sdk/issues/2438,我不确定它是否已修复,因为我不得不处理它。如果仍然存在,请从https://github.com/firebase/firebase-ios-sdk/issues/2438#issuecomment-469472087

进行修复

在后端:

https://fcm.googleapis.com/fcm/send称为旧协议,请改用HTTP v1开机自检https://fcm.googleapis.com/v1/projects/project_name/messages:send。探索documentation

如何authorize send request

如何compose push content

© www.soinside.com 2019 - 2024. All rights reserved.