1

我通过Azure通知中心收到通知时接收到通知时出现问题。我跟着本教程的步骤: https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-fcm/Azure Hub通知无法发送到FCM

在这个时候,一些问题的NuGet依赖冲突结束后,我经历了火力地堡控制台正确地接收到通知。但是,Azure通知中心的“测试发送”选项似乎发送消息,但设备未收到通知。

在此之后其他教程送Azure的通知与FCM服务 https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started,一些步骤似乎不是可能的Xamarin.Android,像的build.gradle加入依赖性。

如何将这些更改纳入Xamarin.Android项目?

回答

1

杰拉德,

,你会得到你的消息的内容的方式从火力地堡控制台发送和测试发送选项Azure的通知集线器时是不同的。

正如您在Xamarin turorial with FCM看到,让我们做下面的消息内容:

public override void OnMessageReceived(RemoteMessage message) 
{ 
    Log.Debug(TAG, "From: " + message.From); 
    Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body); 
} 

但是使用测试发送因为GetNotification()将是空的时候,它不会工作。

当使用测试发送我们发送以下有效载荷:

{"data":{"message":"Notification Hub test notification"}} 

现在如何让你的信息?如果你看看RemoteMessage你会注意到以下Data财产:public IDictionary<string, string> Data { get; }

您可以检索使用Data财产的消息中,如波纹管:

public override void OnMessageReceived(RemoteMessage remoteMessage) 
{ 
    Log.Debug(TAG, "From: " + remoteMessage.From); 

    if (remoteMessage.Data.ContainsKey("message")) 
    { 
     Log.Debug(TAG, "Notification Message: " + remoteMessage.Data["message"]); 
    } 
}