接受的答案是好的,您可以通過使用標籤解決大部分的要求:
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我只是像使用任何用戶一樣使用他們的基本實現,這是否有必要,如果有的話,任何鏈接到哪裏啓用? –