如何在 Cordova、Appcelerator 等中使用 Parse Push [英] How to use Parse Push with Cordova, Appcelerator, etc

查看:24
本文介绍了如何在 Cordova、Appcelerator 等中使用 Parse Push的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Parse 的 JavaScript SDK 不支持注册推送通知,但 Parse 知道如何向 iOS 和 Android 设备发送推送.有什么方法可以设置为 iOS、Android 等推送?

Parse's JavaScript SDK doesn't have support for registering for push notifications, but Parse knows how to send pushes to iOS and Android devices. Is there any way to get set up for push with iOS, Android, etc?

推荐答案

Parse 的 JS SDK 确实没有直接支持注册推送通知的设备,但系统记录得足够好,不应该很难逆向工程(我已经看到它成功完成).您可以通过为该设备创建 Installation 对象来告诉 Parse 您可以向其发送推送的设备.此类具有众所周知的字段,这些字段已记录.在 JavaScript 中,此类被预定义为 Parse.Installation.要在 iOS 上为推送注册您的设备,请设置以下字段:

It's true that Parse's JS SDK doesn't have direct support for registering a device for push notifications, but the system is documented well enough that it shouldn't be difficult to reverse engineer (I've seen it done successfully). You tell Parse about a device to which you can send a push by creating an Installation object for that device. This class has well-known fields which are documented. In JavaScript, this class is pre-defined as Parse.Installation. To register your device for push on iOS, set the following fields:

  • deviceType:"ios"
  • deviceToken:ApplicationDelegate 方法返回的第二个参数的十六进制字符串 application:didRegisterForRemoteNotificationsWithDeviceToken:
  • timeZone(可选):TZ 数据库格式时区(例如 America/Los_Angeles).仅当您想使用 本地推送调度
  • badge(可选):如果您发送增加徽章计数的推送,您需要使用它来告诉 Parse 设备上当前的徽章计数是多少.这让我们知道从什么开始增加.
  • deviceType: "ios"
  • deviceToken: a hex64 string of the second parameter returned in the ApplicationDelegate method application:didRegisterForRemoteNotificationsWithDeviceToken:
  • timeZone (optional): a TZ database format time zone (e.g. America/Los_Angeles). This is only necessary if you want to use local push scheduling
  • badge (optional): If you send pushes that increment badge counts, you need to use this to tell Parse what the current badge count on the device is. This lets us know what to increment from.

要注册 Android 设备,请使用 Parse 的 GCM 发送者 ID (1076345567071) 请求 GCM 令牌.然后使用以下字段创建 Parse.Installation:

To register an android device, request a GCM token with Parse's GCM sender ID (1076345567071). Then create a Parse.Installation with the following fields:

  • deviceType:"android"
  • pushType:"gcm"
  • deviceToken:com.google.android.c2dm.intent.REGISTRATION 意图返回的 "registration_id" 额外.
  • timeZone(可选):TZ 数据库格式时区(例如 America/Los_Angeles).仅当您想使用 本地推送调度
  • deviceType: "android"
  • pushType: "gcm"
  • deviceToken: the "registration_id" extra returned by the com.google.android.c2dm.intent.REGISTRATION intent.
  • timeZone (optional): a TZ database format time zone (e.g. America/Los_Angeles). This is only necessary if you want to use local push scheduling

主要的警告是,您需要在本地保存 Parse.Installation,并且仅在首次创建 Installation 或检测到更改时才发送新请求;否则每次启动应用时都会浪费 API 请求.

The main caveat is that you'll want to save your Parse.Installation locally and only send new requests when the Installation is first created or you have detected changes; otherwise you'll waste API requests every time your app is launched.

这篇关于如何在 Cordova、Appcelerator 等中使用 Parse Push的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆