我有兩個答案,你可以嘗試。他們都要求你指定日期和時間,但你可以使用明天(或真正的任何一天)快速設置的日期方面。
首先,使用原生的JavaScript SDK:
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(getRandomArbitrary(0,23),getRandomArbitrary(0,59),getRandomArbitrary(0,59));
var dayAfterTomorrow = new Date();
dayAfterTomorrow.setDate(tomorrow.getDate() + 1);
Parse.Push.send({
channels: [ "my channel" ],
data: {
alert: "push content here"
},
push_time: tomorrow,
expiration_time: dayAfterTomorrow
}, {
success: function() {
// Push was successful
console.log("successfully sent push out");
status.success("Push away!");
},
error: function(error) {
// Handle error
console.log("got an error");
console.log("Error: " + error.code + " " + error.message);
}
});
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
其次,根據this Parse post from a year ago,還有他們的SDK中的JavaScript,不會做本地時區推的錯誤。你需要使用他們的REST API:
Parse.Cloud.httpRequest({
method: "POST",
headers: {
"X-Parse-Application-Id": YOUR_APP_ID,
"X-Parse-REST-API-Key": REST_API_KEY,
"Content-Type": "application/json"
},
body: {
"where": query,
"push_time": "2013-08-26T12:00:00", // format this as a STRING, not a Date Object
"data": {
"alert": "Local push notification"
}
},
url: "https://api.parse.com/1/push"
}).then(function() {
console.log("Successful push");
}, function(error) {
console.log(error);
});
我沒有嘗試過的REST API代碼,但我知道JavaScript的SDK代碼工作,因爲我使用的是在我的一個項目。我不確定它是否將本地時間發送給用戶,但這不是我寫的項目的要求。
您是否找到解決方案? – 2015-01-19 10:26:56