用firebase和php推送通知

时间:2018-05-23 11:44:33

标签: javascript php firebase firebase-cloud-messaging push

我遇到firebase和php的推送通知问题,推送通知会出现在用户手机上,但如果点击用户手机上的推送本身什么都不做。

我希望它会导致内容的页面,但推送不会导致用户

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);
       }
   });
}

我需要推送通知是可点击的,并引导用户进入推送通知通知用户的页面

0 个答案:

没有答案