接受的答案是好的,您可以通过使用标签解决大部分的要求:
OneSignal.push(function() {
/* These examples are all valid */
OneSignal.sendTag("key", "value");
OneSignal.sendTag("key", "value", function(tagsSent) {
// Callback called when tags have finished sending
});
OneSignal.sendTag("key", "value").then(function(tagsSent) {
// Callback called when tags have finished sending
});
});
但你要编辑的设备信息的情况下,没有办法(今天的)来编辑与WebPush SDK的设备元数据。我需要定期更新位置,而且我不想使用标签。所以,我把PUT请求https://onesignal.com/api/v1players
这样的:
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") { //ie8 ie9
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
};
//then every time I needed to update the device
var url = 'https://onesignal.com/api/v1/players/' + playerId;
var xhr = createCORSRequest('PUT', url);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onload = function() {}; //success
xhr.onerror = function() {}; //error
var deviceInfo = {
"app_id": oneSignalAppId,
"timezone": (currentDateTime.getTimezoneOffset()) * -60, //offset from utc
//whatever fields you need to update
};
xhr.send(JSON.stringify(deviceInfo));
你请求的模式设置为“无CORS”取得与CORS资源禁用? –
你可以给我们你的页面URL从哪里你尝试集成onesignal? –
@JoshBeam我只是像使用任何用户一样使用他们的基本实现,这是否有必要,如果有的话,任何链接到哪里启用? –