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"]); 
    } 
}