CrossFirebasePushNotification.现在的OnNotificationReceived andr



我可以使用Google Firebase控制台成功地向我的应用程序发送通知,但打开事件从未启动(在Visual Studio 2019中运行的Android模拟器(

这是我的MainApplication.cs文件,为简洁起见进行了简化:

public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
CrossCurrentActivity.Current.Init(this);

// these events fire as expected
CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
{
};
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
};
// this doesn't
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
};

我使用的是FirebasePushNotificationsPlugin,我的代码基于它们提供的示例。

Xamarin和移动开发对我来说是全新的,因为我不确定问题出在哪里,所以我不愿意发布大量的代码,其中大部分可能都无关紧要。然而,由于有些活动很成功,有些则不然,这似乎是一个很好的开始。

更新-为了清晰起见,我添加了一些额外信息:

我还有一个SplashActivity.cs,它具有MainLauncher = true属性:

public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
Log.Debug(TAG, "SplashActivity.OnCreate");

FirebasePushNotificationManager.ProcessIntent(this, Intent);
}

...

protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
FirebasePushNotificationManager.ProcessIntent(this, intent);
}

还有MainActivity.cs,它包含以下内容:

protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}

目前这就是我的工作方式在onCreate this:中添加主应用程序

CrossCurrentActivity.Current.Init(this);
//Set the default notification channel for your app when running Android Oreo
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
//Change for your default notification channel id here
FirebasePushNotificationManager.DefaultNotificationChannelId = "DefaultChannel";

//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
}

//If debug you should reset the token each time.
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this, false);
#endif
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{

};
}
}
}

在主要活动中:

protected override void OnCreate(Bundle savedInstanceState)
{
FirebasePushNotificationManager.ProcessIntent(this, Intent);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
FirebasePushNotificationManager.ProcessIntent(this, intent);
}

我认为您的活动不是主要的启动器活动。

MainLauncher = true声明活动中的FirebasePushNotificationManager.ProcessIntent(Intent)

请阅读更多线程以获取更多信息:

OnNotificationOpened从未执行。

CrossFirebasePushNotification。现在的OnNotificationOpened事件未启动

相关内容

  • 没有找到相关文章

最新更新