这个想法是浏览器的直接权限请求将在ajax之后出现,并且如果给用户通知权限,onesignal将返回用户ID,因为我需要将其添加到数据库中以发送自定义的通知。 ajax成功后,onesignal会在图像中产生错误
我正在使用:
$.ajax({
url: '../php/assi.php',
data: {ma_id:ma_id},
type: 'POST',
dataType: "html",
success:function(retorno){
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "*******************************",
autoRegister: true ,
promptOptions: {
},
welcomeNotification: {
},
notifyButton: {
enable: true
}
}]);
OneSignal.push(function() {
OneSignal.on('subscriptionChange', function (isSubscribed) {
console.log("The user's subscription state is now:",isSubscribed);
OneSignal.push(function() {
OneSignal.getUserId(function(userId) {
console.log("OneSignal User ID:", userId);
$.post("../php/ma_notifica.php",
{
userId: userId,
ma_id: ma_id,
action: 'add'
}, function(data)
{
});
});
});
});
});
}
});
答案 0 :(得分:0)
已解决
在public_html
OneSignalSDKUpdaterWorker.js
OneSignalSDKWorker.js
manifest.json
$.ajax({
url: '../php/assi.php',
data: {man_id:man_id},
type: 'POST',
dataType: "html",
success:function(retorno){
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "************************************",
safari_web_id: "web.onesignal.auto.********************",
autoRegister: false ,
promptOptions: {
actionMessage: "Receive Notifications?",
acceptButtonText: "Yes",
cancelButtonText: "no"
},
notifyButton: {
enable: true
}
}]);
OneSignal.push(function() {
OneSignal.on('subscriptionChange', function (isSubscribed) {
console.log("The user's subscription state is now:",isSubscribed);
OneSignal.push(function() {
OneSignal.getUserId(function(userId) {
console.log("OneSignal User ID:", userId);
$(this).text('Assinatura realizada com sucesso!');
$.post("../php/man_ass_notif.php",
{
userId: userId,
man_id: man_id,
action: 'add'
}, function(data)
{
});
});
//Send Tags
OneSignal.sendTags({
userId: userId,
user_type: man_id,
}).then(function(tagsSent) {
console.log(tagsSent);
window.location.reload();
});
//Send Tags
});
});
});
}
});