我遇到了一直试图调试几天的问题,但失去了希望。我有一个带Firebase后端的Ionic移动应用程序。我正在尝试编写Twilio聊天。我正在尝试使其暂时适用于iOS。这是我到目前为止所做的:
当应用未打开时,为什么我没有收到通知?逻辑显然很有效,因为当我打开应用程序时,Firebase SDK确实会收到通知。对于任何应用程序设置,似乎也都没有问题,因为直接从Firebase发送通知时,我能够在应用程序处于后台时收到通知。
这是我的后端代码,该代码生成Twilio访问令牌:
// Twilio credentials and ids are defined here...
const chatGrant = new ChatGrant({
serviceSid: twilioServiceSid,
pushCredentialSid: credentialSid
});
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret, {
identity: uid
});
token.addGrant(chatGrant);
return token.toJwt();
这是我的Ionic代码的摘要,该代码从设备中获取了FCM令牌并将其传递给Twilio
async getToken(): Promise<string> {
let token: string;
if (this.platform.is('ios')) {
const hasPermission = await this.firebaseNative.hasPermission();
if (!hasPermission) {
try {
await this.firebaseNative.grantPermission();
} catch (e) {
console.error('Error granting permission', e);
throw e;
}
}
try {
token = await this.firebaseNative.getToken();
} catch (e) {
console.error('Error getting FCM token', e);
throw e;
}
}
return token;
}
setPushRegistrationId(token: string) {
return this.twilioClient.setPushRegistrationId('fcm', token);
}
getToken().then(async (token) => {
console.log('fcm token: ' + token);
setPushRegistrationId(token)
.then(() => console.log('Added registration token'))
.catch(e => console.error('Error registering fcm token', e));
}).catch(e => {
console.error('Error getting FCM token', e);
console.error(e);
});
请帮助!谢谢?
答案 0 :(得分:1)
我最近发现Twilio仅发送用于FCM的数据推送。这意味着您需要处理背景推送并决定是否在本地显示它们。