我正在使用 Twilio 可编程聊天,并希望将推送通知发送到移动应用程序(iOS、Android)和网络应用程序。我遵循了Twilio中给出的步骤 ,但我也没有在网络和移动应用程序中收到通知。以下是我实现的代码。
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js"></script>
<script src="firebase-messaging-sw.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "******************",
authDomain: "*****.firebaseapp.com",
databaseURL: "https://******.firebaseio.com",
projectId: "******",
storageBucket: "******.appspot.com",
messagingSenderId: "***************"
};
firebase.initializeApp(config);
</script>
在用户登录期间,我正在执行以下操作
/* Generating token for Twilio chat */
$scope.URL = Path + "/twilio/chat/generateToken";
var data = {"identity":localStorage.userId,"deviceId":guid(),"pushCredentialSid":"**********"}
RestAPIService.post($http,data,$scope,$scope.URL, function ( responsesData ) {
if(responsesData.data.status == "success"){
var twilioToken = responsesData.data.token;
Twilio.Chat.Client.create(twilioToken).then(function(twilioClient) {
twilioChatClient = twilioClient;
// Twilio notification
firebase.initializeApp(config);
if (firebase && firebase.messaging()) {
// requesting permission to use push notifications
firebase.messaging().requestPermission().then(function() {
console.log ("Notification permission granted.");
// getting FCM token
firebase.messaging().getToken().then(function(fcmToken) {
console.log ("token is:" + fcmToken);
// continue with Step 7 here
// passing FCM token to the `chatClientInstance` to register for push notifications
twilioChatClient.setPushRegistrationId('fcm', fcmToken);
// registering event listener on new message from firebase to pass it to the Chat SDK for parsing
/* firebase.messaging().onMessage(function(payload){
twilioChatClient.handlePushNotification(payload);
}); */
}).catch(function(err) {
// can't get token
console.log(err);
});
}).catch(function(err){
// can't request permission or permission hasn't been granted to the web app by the user
console.log(err);
});
} else {
// no Firebase library imported or Firebase library wasn't correctly initialized
}
/* Twilio notification */
});
}
});
我不确定,如何进一步进行,也不知道我是否错过了什么。如果有人已经实现了从网络应用程序到移动应用程序的推送通知,请指导我进一步进行。