![](/img/trans.png)
[英]Push notification with Xamarin.Forms and Azure: the devices are not registered
[英]Xamarin.Forms AppCenter Push Notification
目前,我正在将Xamarin.Forms与AppCenter Push一起使用,以获取通知。 我的最终目标是拥有以下功能:
如果应用已关闭或打开,我会收到一条通知(在通知列表中列出),然后单击将用户重定向到某个页面。 根据提供的自定义数据,我将把他重定向到另一个页面。 在AppCenter Push文档中的Xamarin.Forms中发现,如果打开应用程序,则我的方法应该具有新的通知事件,但不会-显示通知。
这是我非常简单的代码: 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));
}
然后我有: MainActivity.cs
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
Push.CheckLaunchedFromNotification(this, intent);
}
努力实现这一简单方案,我遇到了不同的问题:
如果您需要更多信息,请告诉我! 提前致谢!
尝试在android中执行通知事件。 要将参数从Android传递到Forms App,可以使用MessagingCenter。 在下面的通知接收事件中,您可以从通知有效负载中提取数据,然后使用MessagingCenter传递给表单应用程序。 确保您已完成以下步骤。
在MainActivity的OnCreate方法中,注册并订阅PushNotification。
if (!AppCenter.Configured)
{
Push.PushNotificationReceived += (sender, e) =>
{
};
}
在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.