解析推送通知包含用户时间戳的时区 [英] Parse Push Notification Include Users TimeZone in Push-Time
问题描述
如果我想发送包含datetime的推送通知,是否可以包含用户的时区?
Is it possible to include the users' timezone if I want to send a push notification containing a datetime?
Parse.Push.send({
where: query, // Set our Installation query
data: {
type: 2, // new applications push
applicationID: applicationID,
startTime: startTime,
"alert" : {
"title-loc-key": "SUCCESSFUL_TITLE",
"loc-key": "SUCCESSFUL_MESSAGE",
"loc-args": [startTime]
},
"sound": "default",
"content-available" : "1",
"badge" : 'Increment'
}
所以推送消息在01.02.2016,19:00 Uhr显示一段时间像[一些文本]
我用cloudcode中的moment.js硬编码一个时区 - 但是对于未来,来自不同地区的不同用户应该在其各自的时区中获取日期和时间信息...可以通过Parse.Push调用实现这一点,而不需要在安装表中进行手动迭代?
So the push message displays a time like "[some text] at 01.02.2016, 19:00 Uhr". I hardcoded a timezone with moment.js in the cloudcode - but for the future, different users from different regions should get date and time information in their respective timezones... Is it possible to achieve this with the Parse.Push call and without manual iteration over the Installation table?
推荐答案
根据Parse.com文档,有一个 安装
对象,您可以通过 timeZone
参数获取用户的时区。
According to the Parse.com documentation, there is an Installation
object in which you can get the user's time zone via the timeZone
parameter.
timeZone
:目标设备所在的当前时区。每次从设备保存安装对象时,都会同步该值。
timeZone
: The current time zone where the target device is located. This value is synchronized every time an Installation object is saved from the device.
在REST API文档中的其他地方,他们谈论本地推送计划,并以术语描述 Installation.timeZone
参数的IANA时区ID,例如 America / New_York
或 America / Los_Angeles
。这些ID与时刻区使用的ID相同。
Elsewhere in the documentation for their REST API, they talk about local push scheduling, and describe the Installation.timeZone
parameter in terms of IANA time zone IDs, such as America/New_York
or America/Los_Angeles
. These IDs are the same ones that moment-timezone uses.
首先,您需要加载时刻和 moment-timezone ,以及一些时区数据。可能你想要 moment-timezone-2010-2020.js
文件。
So first you need to load moment and moment-timezone, along with some time zone data. Probably you want the moment-timezone-2010-2020.js
file.
然后你可以做这样的事情:
Then you can do something like this:
var timeZone = Installation.timeZone; // or however you get this from Parse.com
var startTime = '2015-09-27T12:00:00Z'; // ISO-8601 format
var m = moment(startTime).tz(timeZone); // converted to the user's time zone
var s = m.calendar(); // or m.format, or whatever you want
var message = "Hi Bob, your event starts " + s;
然后推出您在问题中显示的消息
Then push out the message as you showed in your question
这篇关于解析推送通知包含用户时间戳的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!