注册xam.plugin.pushnotification时出错



我在我的xamarin.forms项目中使用xam.plugin.pughnotification

我的主要活动

 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>("mysendernumbers");
            StartPushService();
            CrossPushNotification.Current.Register();
        }
        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);
        }
    }

我的pcl中的听众

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;
    }
}

}

在app.cs(pcl)中注册(尝试LOL)

 public App()
    {
        InitializeComponent();
        CrossPushNotification.Current.Register();
        MainPage = new NavigationPage(new Views.Splash2());
    }

尝试注册后,我会遇到此错误。...(在Onerror方法中)

.jniObjectReference实例,Java.interop.jnimethodinfo方法,Java.interop.jniargumentValue* args)[0x00069] in&lt; 259999cc1fde6426b852c2c2c2c2c2c2e027711c254>:0 n at android.runt.c.runt.c.runtptrime comtrimn.c。 system.intptr jmethod,iid.zzc.zzb(未知来源) n tat com.google.android.gms.iid.zzc.zza(未知来源) n n tat com.google.google.android.gms.gms.iid.instance.zzc(源) n tat com.google.android.gms.iid.instanceid.getToken(未知来源) n tat com.google.android.android.gms.gcm.gcm.gcmpubsub.subsubl.subscribe(subscribe)意图服务。答:65) n tat android.os。handler.dispatchMessage(Handler.java:102) n tat android.os.looper.loop(looper.java:146) n n tat android.os.handlerthread.run(handlerthread.java:61) - pushnotificationRegistationInterservice

我想这不是您一直在寻找的确切答案,但是您,我和其他许多人都在使用此软件包。如果您不公开使用PushNotification,则应强烈考虑迁移。

最新更新