[英]Xamarin.Forms AppCenter Push Notification
Currently, I am using Xamarin.Forms with AppCenter Push, in other, to have notifications. 目前,我正在将Xamarin.Forms与AppCenter Push一起使用,以获取通知。 My end goal is to have this functionality:
我的最终目标是拥有以下功能:
If the app is closed OR opened I can receive a notification (listed inside notifications list) and on click, redirect the user to a certain page. 如果应用已关闭或打开,我会收到一条通知(在通知列表中列出),然后单击将用户重定向到某个页面。 Based on the custom data provided, I am going to redirect him to a different page.
根据提供的自定义数据,我将把他重定向到另一个页面。 What I've found in AppCenter Push docs for Xamarin.Forms are that if the app is opened, my method should have the new notification event, but it will not - display the notification.
在AppCenter Push文档中的Xamarin.Forms中发现,如果打开应用程序,则我的方法应该具有新的通知事件,但不会-显示通知。
Here is my very simple code: App.xaml.cs 这是我非常简单的代码: App.xaml.cs
protected override async void OnStart()
{
await Push.SetEnabledAsync(true);
if (!AppCenter.Configured)
{
Push.PushNotificationReceived += (sender, e) =>
{
DependencyService.Resolve<IMessageService>().LongAlert("TESTT");
// Add the notification message and title to the message
string summary = $"Push notification received:" +
$"\n\tNotification title: {e.Title}" +
$"\n\tMessage: {e.Message}";
// If there is custom data associated with the notification,
// print the entries
if (e.CustomData != null)
{
summary += "\n\tCustom data:\n";
foreach (string key in e.CustomData.Keys)
{
summary += $"\t\t{key} : {e.CustomData[key]}\n";
}
}
// Send the notification summary to debug output
Debug.WriteLine(summary);
};
}
AppCenter.Start("", typeof(Push));
}
Then I have: MainActivity.cs 然后我有: MainActivity.cs
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
Push.CheckLaunchedFromNotification(this, intent);
}
Struggling to implement this simple scenario I have faced different problems: 努力实现这一简单方案,我遇到了不同的问题:
If you need any more information, please do let me know! 如果您需要更多信息,请告诉我! Thanks in advance!
提前致谢!
Try doing the notifications events in the android. 尝试在android中执行通知事件。 To pass the parameters from Android to Forms App, you can use MessagingCenter.
要将参数从Android传递到Forms App,可以使用MessagingCenter。 In the below, notification received event, you can extract the data from the notification payload and pass to forms app using MessagingCenter.
在下面的通知接收事件中,您可以从通知有效负载中提取数据,然后使用MessagingCenter传递给表单应用程序。 Ensure you have done the below steps..
确保您已完成以下步骤。
In the OnCreate method of your MainActivity, register and subscribe for PushNotification. 在MainActivity的OnCreate方法中,注册并订阅PushNotification。
if (!AppCenter.Configured)
{
Push.PushNotificationReceived += (sender, e) =>
{
};
}
In the NewIntent method, 在NewIntent方法中,
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
Push.CheckLaunchedFromNotification(this, intent);
var type = intent.GetStringExtra("type");
if ((!string.IsNullOrEmpty(type) && object.Equals(type, "notification")))
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.