Я использую xam.plugin.pushnotification в своем проекте xamarin.forms
моя основная деятельность
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
//inicializa imageCircle
ImageCircleRenderer.Init();
//inicializa o mapa
global::Xamarin.FormsMaps.Init(this, bundle);
//shared Preferences
App.Init(new AndroidUserPreferences());
//Gerenciador de memória
CachedImageRenderer.Init();
try
{
AppContext = this.ApplicationContext;
CrossPushNotification.Initialize<CrossPushNotificationListener>("my sender");
StartPushService();
}
catch (Exception e)
{
var s = e.Message;
}
AndroidUserPreferences sharedPref = new AndroidUserPreferences();
if ( sharedPref.GetString("token") == " ")
{
GetTokenTask myTask = new GetTokenTask();
myTask.Execute(this);
}
LoadApplication(new App());
}
public static void StartPushService()
{
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
public static void StopPushService()
{
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
Мой слушатель в моем ПК
public class CrossPushNotificationListener : IPushNotificationListener
{
public void OnMessage(JObject values, DeviceType deviceType)
{
Debug.WriteLine("Message Arrived");
}
public void OnRegistered(string token, DeviceType deviceType)
{
Debug.WriteLine(string.Format("Push Notification - Device Registered - Token : {0}", token));
}
public void OnUnregistered(DeviceType deviceType)
{
Debug.WriteLine("Push Notification - Device Unnregistered");
}
public void OnError(string message, DeviceType deviceType)
{
Debug.WriteLine(string.Format("Push notification error - {0}",message));
}
public bool ShouldShowNotification()
{
return true;
}
}
}
Регистрация (пробуем LOL) в app.cs (PCL)
public App()
{
InitializeComponent();
CrossPushNotification.Current.Register();
MainPage = new NavigationPage(new Views.Splash2());
}
Я зарегистрировал свой проект в firebase, используя имя пакета, затем я создал там проект и получил идентификатор отправителя ... НО ... после вызова "cross ... current.register ()" где-то (он не отображается я где), у меня есть исключение
ФАТАЛЬНОЕ НЕОБРАБОТАННОЕ ИСКЛЮЧЕНИЕ: System.TypeLoadException: не удалось разрешить тип с токеном 0100005a (из typeref, класс / сборка Android.Gms.Gcm.Iid.InstanceID, Xamarin.GooglePlayServices.Gcm, Version = 1.0.0.0, Culture = нейтральный, PublicKeyToken = нулевой)
мне нужно установить xamarin.gcm в мой проект pcl? теперь это только в моем андроид-проекте