简体   繁体   English

将通知从Mixpanel仪表板推送到Android Cordova应用

[英]Push notification from Mixpanel dashboard to Android Cordova app

I am successfully sending Push Notifications from the Mixpanel Dashboard to a Cordova app on both iOS and Android devices, using phonegap-plugin-push . 我已使用phonegap-plugin-push成功将推送通知从Mixpanel仪表板发送到iOS和Android设备上的Cordova应用程序。

However, the title and body values entered in the default fields only appear on iOS devices. 但是,在默认字段中输入的标题和正文值仅出现在iOS设备上。

For the notification to appear on Android devices, I currently need to include a custom payload in Mixpanels "Custom Data": 为了使通知显示在Android设备上,我目前需要在Mixpanels“自定义数据”中包含自定义有效负载:

{
"title":"Title for Android only",
"body":"Content for Android only"
}

This is an error prone step for any non-technical using Mixpanel to send notifications. 对于任何使用Mixpanel发送通知的非技术人员,这都是容易出错的步骤。

Does someone know an easier way to do this? 有人知道这样做更简单的方法吗?

The short answer here is that Cordova/Phonegap and similar third party frameworks are not 100% optimized for Mixpanel functionality (although they work pretty great), and as such you'll need to generate separate push notifications for both iOS and Android in your Mixpanel project. 简短的答案是,Cordova / Phonegap和类似的第三方框架并未针对Mixpanel功能进行100%优化(尽管它们工作得非常好),因此,您需要在Mixpanel中为iOS和Android分别生成推送通知项目。

Providing context, all iOS pushes regardless of app deliver a JSON payload to APN using the same keys to deliver their messages (alert, badge, sound). 提供上下文,所有iOS推送(无论应用程序是什么)都使用相同的键来传递其消息(警报,徽章,声音)给APN传递JSON负载。 However, the keys that Android apps process for incoming GCM pushes are entirely dependent on how the GCM receiver is established, and therein lies the problem here. 但是,Android应用为传入GCM推送处理的密钥完全取决于GCM接收器的建立方式,这就是问题所在。

Mixpanel's Android SDK initializes pushes and uses a GCM receiver that is specific to Mixpanel messages, and fully expects its custom keys (mp_message, mp_title) in order to render the notification. Mixpanel的Android SDK会初始化推送并使用特定于Mixpanel消息的GCM接收器,并完全期望其自定义键(mp_message,mp_title)以呈现通知。 The webapp reformats the message input to meet these key requirements ( http://bit.ly/1OGgU1y ) Webapp重新格式化消息输入以符合这些关键要求( http://bit.ly/1OGgU1y

However, the Phonegap GCM receiver expects different keys as you've noticed. 但是,正如您所注意到的,Phonegap GCM接收器期望使用不同的键。 I'd recommend referring to the phonegap github page in order to get more context into the expected push format and behavior (looks like they expect "title" and "message" as the keys): http://bit.ly/1KDScye 我建议参考phonegap github页面,以使更多上下文包含在预期的推送格式和行为中(看起来他们希望键为“ title”和“ message”): http : //bit.ly/1KDScye

Unfortunately, what this means is that the Android app is not optimized to receive the default, web-app generated Mixpanel pushes, although your iOS one is. 不幸的是,这意味着Android应用程序并未进行优化以接收默认的,由Web应用程序生成的Mixpanel推送,尽管您的iOS设备是。 Mixpanel's SDKs are intended to maximize capabilities for that platform, and it isn't guaranteed that Cordova or similar JS frameworks will translate 100%. Mixpanel的SDK旨在最大化该平台的功能,并且不能保证Cordova或类似的JS框架可以100%转换。

So to conclude - Creating a message in the Mixpanel push editor will send to iOS, but for Android you'll need to use the custom JSON payload in a separate notification, including keys that the phonegap GCM receiver is compatible with. 总结一下-在Mixpanel推送编辑器中创建消息将发送到iOS,但是对于Android,您需要在单独的通知中使用自定义JSON有效负载,包括phonegap GCM接收器兼容的密钥。

If its help to anyone this is how I solved the problem in phonegap-plugin-push 如果对任何人有帮助,这就是我解决了phonegap-plugin-push问题的方法

you need to modify two files 您需要修改两个文件

  1. GCMIntentService.java GCMIntentService.java

    private String normalizeKey(String key) { 私人字串normalizeKey(字串键){
    if (key.equals(BODY) || key.equals(ALERT) || key.equals(MP_MESSAGE) || key.equals(GCM_NOTIFICATION_BODY)) { // added MP_MESSAGE if(key.equals(BODY)|| key.equals(ALERT)|| key.equals(MP_MESSAGE)|| key.equals(GCM_NOTIFICATION_BODY)){//添加了MP_MESSAGE

  2. PushConstants.java PushConstants.java

    public static final String MP_MESSAGE = "mp_message"; public static final String MP_MESSAGE =“ mp_message”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM