-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.js
38 lines (33 loc) · 1 KB
/
notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Initialize Firebase - https://firebase.google.com/docs/web/setup
var config = {
apiKey: "******************",
authDomain: "******.firebaseapp.com",
databaseURL: "https://******.firebaseio.com",
projectId: "*******",
storageBucket: "*******.appspot.com",
messagingSenderId: "***********"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
// function fcm_get_fcm_push_token() {
// return messaging.getToken();
// }
// function print_fcm_token() {
// fcm_get_fcm_push_token().then(console.log);
// }
messaging.requestPermission()
.then(function() {
return messaging.getToken();
})
.then(function(token) {
// send rest call to add to database
$.ajax('https://phpnot-97be7.firebaseio.com/pushtokens/'+token+'.json', {
method: 'PUT',
data: 'true',
error: function(err) {
}
});
})
.catch(function(err) {
console.log('Permission denied');
});