我正着手建立一个Xamarin Forms项目,用于概念验证,目的是让Android模拟器中运行的Android应用程序注册并接收通过Azure通知中心发送的Google云端通知。
在研究这个时,我发现了一些示例代码,它假定后端使用Microsoft Azure的移动服务后端。 如果可能的话,我宁愿不在移动服务后端的客户端代码中依赖。 但是,使用Azure通知中心时,这可能是不可避免的(或不可取的)。 这是我提出这个问题的核心问题。
下面链接的教程显示了使用Xamarin表单应用程序注册和接收通知的方法,该应用程序依赖于Azure移动服务后端。
https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-xamarin-forms-get-started-push/
然而,第二个教程展示了一种方法,其中移动客户端应用程序(使用Xamarin Android开发)注册到Google消息传递云而不是Azure通知中心。
https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote_notifications_in_android/
我要解决的问题是试图找出哪种方法能够使Xamarin表单应用程序注册并接收通过Azure通知中心推送的通知。 当通过Azure通知中心(配置了正确的Google消息传递API凭据)发送通知时,第二个教程的方法(设备注册直接通过Google云推送通知)是否有效?或者我错过了什么?
换句话说,采用第二种方法,我是否为自己的生活困难?
我的重点是开发使用Xamarin表单,但Android作为初始原型的主要设备类型,概念证明,然后在稍后阶段转移到iOS和Windows Universal 10。
I am embarking on setting up a Xamarin Forms project for proof of concept with an aim of having an Android app running in the Android emulator registering and receiving google cloud notifications sent via Azure's notification hub.
In researching this I have found some sample code which assumes a backend which uses Microsoft Azure's Mobile Services back end. I'd prefer not to have a dependency in my client code on Mobile Services backend if possible. However, maybe this is unavoidable (or inadvisable) when using Azure Notification Hubs. That is really the central issue I am raising with this question.
The tutorial linked below shows an approach to register and receive notifications using a Xamarin forms app which is dependent on the Azure Mobile Services backend.
https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-xamarin-forms-get-started-push/
Whereas, this second tutorial shows an approach where the mobile client app (developed using Xamarin Android) registers to the Google messaging cloud rather than Azure notification hubs).
https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote_notifications_in_android/
Where I am coming unstuck is trying to figure out which is the right approach to enabling a Xamarin forms app to register and receive notifications which are pushed via Azure notification hub. Will the approach of the 2nd tutorial (device registers for push notifications directly with Google cloud) work when notifications are sent via Azure Notification Hubs (configured with the correct API credentials for google messaging) or am I missing something ?
In other words am I making life difficult for myself by adopting the 2nd approach ?
My focus is on developing using Xamarin forms but with Android as the lead device type for initial prototype , proof of concept and then moving on to iOS and Windows Universal 10 at a later stage.
最满意答案
我的2美分。
使用Azure通知中心的重点是抽象出处理Google和iOS推送通知系统的需要。 由于您计划最终同时执行iOS和Android,我建议您通过Azure注册。
注册设备时,Azure将处理iOS反馈通道,这很好,您可以在Azure中使用消息模板,这意味着您可以发送单个通知中心消息,它将自动转换为Android的GCM期望看到的消息和另一个消息iOS'APNS希望收到的消息(他们都期望不同的通知消息格式)。
由于听起来无论您选择哪个选项,您计划通过Azure发送消息,您将不得不处理相同的Notification Hub限制,这意味着您无法通过本机服务器接口直接注册获得太多收益(限制)在消息可以拥有的标签数量是我主要考虑的事情)。
如果您想直接从设备注册,也可以使用两个平台的库,或者您可以像我们一样,让移动设备调用您自己的后端服务器之一,该服务器可以在将注册请求发送到azure之前进行一些初始处理装置。
*编辑:虽然如果你只是想让某些东西工作,我没有看到直接注册到GCM然后稍后通过Azure切换代码来执行它的问题。
My 2 cents.
The whole point of using Azure Notification Hubs is to abstract away the need to handle Google and iOS push notification systems. Since you are planning to eventually do both iOS and Android, I would suggest registering through Azure.
Azure will handle the iOS feedback channel when registering devices which is nice and you are able to use message templates in Azure which means you can send a single notification hub message and it will be automatically transformed into a message that Android's GCM expects to see and another message that iOS' APNS expects to receive (they both expect different notification message formats).
Since it sounds like no matter which option you choose, you are planning to send messages through Azure, you are going to have to deal with the same Notification Hub limitations, meaning you do not gain much from registering directly through the native server interfaces (limitations in the number of tags a message can have is what I am mainly thinking about).
There is also a library for both platforms if you want to register directly from the device or you can, like we did, have the mobile device call one of your own backend server which can do some initial processing before sending the registration request to azure for the device.
*Edit: Though if you just want to get something working, I do not see a problem with registering directly to GCM and then later on switching out the code to do it through Azure later on.
更多推荐
发布评论