2018-01-10 17:28:30 +03:00
|
|
|
#if !FDROID
|
2017-12-22 06:14:56 +03:00
|
|
|
using System;
|
|
|
|
using Android.App;
|
|
|
|
using Android.Content;
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
using Firebase.Messaging;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using Xamarin.Forms;
|
|
|
|
using XLabs.Ioc;
|
|
|
|
|
|
|
|
namespace Bit.Android
|
|
|
|
{
|
|
|
|
[Service]
|
|
|
|
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
|
|
|
|
public class FirebaseMessagingService : Firebase.Messaging.FirebaseMessagingService
|
|
|
|
{
|
|
|
|
public override void OnMessageReceived(RemoteMessage message)
|
|
|
|
{
|
|
|
|
if(message?.Data == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = message.Data.ContainsKey("data") ? message.Data["data"] : null;
|
|
|
|
if(data == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var obj = JObject.Parse(data);
|
|
|
|
var listener = Resolver.Resolve<IPushNotificationListener>();
|
|
|
|
listener.OnMessage(obj, Device.Android);
|
|
|
|
}
|
|
|
|
catch(JsonReaderException ex)
|
|
|
|
{
|
|
|
|
System.Diagnostics.Debug.WriteLine(ex.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 17:28:30 +03:00
|
|
|
#endif
|