duanfu4446 2018-05-23 11:44
浏览 329

用firebase和php推送通知

I have a problem with firebase and php for push notifications the push notification appears on the user mobile but the push itself if clicked on the user mobile does nothing.

I expect it to lead to the page of the content but the push doesnt get to the user

var config = {
    apiKey: "AIzaSyAXavmNUsgT7UgRIQEdweFXIhBrYTGPvOY",
    authDomain: "tech-miz.firebaseapp.com",
    databaseURL: "https://tech-miz.firebaseio.com",
    projectId: "tech-miz",
    storageBucket: "tech-miz.appspot.com",
    messagingSenderId: "942114086591"
};

firebase.initializeApp(config);
// Retrieve Firebase Messaging object.
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function() {
    console.log('Notification permission granted.');
    // TODO(developer): Retrieve an Instance ID token for use with FCM.
    /*if(isTokenSentToServer()){
        console.log("Token already saved");

    } else {
        getRegToken();
    }*/
    getRegToken();
})
.catch(function(err) {
    console.log('Unable to get permission to notify.', err);
});

function getRegToken() {
    // Get Instance ID token. Initially this makes a network call, once retrieved
    // subsequent calls to getToken will return from cache.
    messaging.getToken()
    .then(function(currentToken) {
        if (currentToken) {
        //sendTokenToServer(currentToken);
        // console.log(currentToken);

        saveToken(currentToken);
        setTokenSentToServer(true);
        //updateUIForPushEnabled(currentToken);
        } else {
            // Show permission request.
            console.log('No Instance ID token available. Request permission to generate one.');
        // Show permission UI.
            setTokenSentToServer(false);
        }
    })
    .catch(function(err) {
        console.log('An error occurred while retrieving token. ', err);
        // showToken('Error retrieving Instance ID token. ', err);
        setTokenSentToServer(false);
    });
}

function setTokenSentToServer(sent) {
    window.localStorage.setItem('sentToServer', sent ? 1 : 0);
}
function isTokenSentToServer() {
    return window.localStorage.getItem('sentToServer') == 1;
}
function saveToken(currentToken){
   $.ajax({
       type: "POST",
       url: "blog/ajax/save.push.notification.php",
       data: "token=" + currentToken,
       success: function (response) {
           console.log(response);
       }
   });
}

I need the push notification to be clickable and lead the user to the page where the push notification is notifying the user about

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 Matlab怎么求解含参的二重积分?
    • ¥15 苹果手机突然连不上wifi了?
    • ¥15 cgictest.cgi文件无法访问
    • ¥20 删除和修改功能无法调用
    • ¥15 kafka topic 所有分副本数修改
    • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
    • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
    • ¥40 串口调试助手打开串口后,keil5的代码就停止了
    • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
    • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档