Xamarin.Forms 来自 Azure 通知中心的 PushNotifications

Xamarin.Forms PushNotifications from Azure Notification Hub

我正在尝试从 Xamarin.Forms 上的 Azure 通知中心接收推送通知。我尝试了 Android 的 Azure 示例。问题是,Azure's tutorial 连接到数据库,该数据库在数据库更改时发送通知。我不想要那个。已经有触发推送通知的 CMS。

那么如何将应用程序连接到通知中心并收听通知?

实际上我现在正在做这件事。不是 Xamarin,而是 Windows Phone 应用程序。希望这可以有所帮助。

  1. 确保您在开发门户中注册了您的应用程序并创建了 WNS 关联。
  2. 完成后,您可以返回到您的移动服务或通知中心,并添加您刚刚从开发门户获得的包 ssid 和客户端密码。
  3. 添加代码以将您的应用与通知中心相关联

    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

    var hub = new NotificationHub("", ""); var result = await hub.RegisterNativeAsync(channel.Uri);

那可以在App.xaml.cs的OnLaunched事件中去。这会将应用程序注册到中心。确保您选择应用程序将在包清单中显示的通知类型(toast..etc..)

  1. 为了执行通知,听起来您可能需要自定义 API 来调用通知中心。这就是我正在做的。当发生特定操作时,我调用自定义 API 并将发出推送。

详细写在下面urlhttps://azure.microsoft.com/en-us/documentation/articles/notification-hubs-windows-store-dotnet-get-started/

如果您不想通知所有人,还有其他一些不错的文档,例如只通知某个类别的订阅者。希望这可以帮助。它可能不是 100% 与 Xamarin 一致,但应该接近。

找到解决方案。我也必须在 Azure 通知中心注册。如果有人卡住了,请按照以下步骤操作:

https://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-notification-hubs-android-get-started/

或者,按照此处 Xamarin 的 "Azure Messaging" 组件中给出的示例:https://components.xamarin.com/gettingstarted/azure-messaging