当我的应用关闭时,我会收到来自FCM的新通知,但是当我点按它时,我的应用会崩溃。当我的应用程序处于后台或前台时,它是可以的,然后他们将打开通知的右页。我不打电话给SendNotification,因为我不想在应用程序处于前台时收到本地通知。
我的fcm服务:
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
ImageCircleRenderer.Init();
IsPlayServicesAvailable();
if (Intent.Extras != null)
{
NotificationSendObject notifcation = new NotificationSendObject();
foreach (var key in Intent.Extras.KeySet())
{
switch (key)
{
case "object_id":
notifcation.objectId = Intent.Extras.GetString(key);
break;
case "notification_id":
notifcation.notificationId = Intent.Extras.GetString(key);
break;
case "object_type":
notifcation.objectType = Intent.Extras.GetString(key);
break;
}
}
if (notifcation.notificationId != null)
{
MessagingCenter.Send(App.CurrentApp, "OnTapNotification", notifcation);
}
}
SecureStorageImplementation.StoragePassword = "*****";
LoadApplication(new App());
}
OnCreate中的通知处理:
<phase>prepare-package</phase>
答案 0 :(得分:1)
我找到了一个解决方案,必须在LoadApplication方法之后调用Intent.Extras。
修正:
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
ImageCircleRenderer.Init();
IsPlayServicesAvailable();
SecureStorageImplementation.StoragePassword = "*****";
LoadApplication(new App());
if (Intent.Extras != null)
{
NotificationSendObject notifcation = new NotificationSendObject();
foreach (var key in Intent.Extras.KeySet())
{
switch (key)
{
case "object_id":
notifcation.objectId = Intent.Extras.GetString(key);
break;
case "notification_id":
notifcation.notificationId = Intent.Extras.GetString(key);
break;
case "object_type":
notifcation.objectType = Intent.Extras.GetString(key);
break;
}
}
if (notifcation.notificationId != null)
{
MessagingCenter.Send(App.CurrentApp, "OnTapNotification", notifcation);
}
}
}