FCM 推送通知在使用离子电容器的 IOS 中不起作用
FCM Push Notification are not working in IOS using Ionic Capacitor
使用 CAPACITOR
和 IONIC
在 Android 上一切正常,但在 IOS 上出现以下错误:
APNS device token not set before retrieving FCM Token for Sender ID 'mySenderId'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 3.2.2
@capacitor/core: 3.2.2
@capacitor/android: 3.2.2
@capacitor/ios: 3.2.2
Installed Dependencies:
@capacitor/cli: 3.2.2
@capacitor/core: 3.2.2
@capacitor/android: 3.2.2
@capacitor/ios: 3.2.2
我可以在我的 Xcode
日志中看到 FCM 令牌,但通知不起作用。
参考文献:
您似乎缺少 APNS 设置并将其与 FCM 连接。只需按照这个很棒的教程:
https://devdactic.com/push-notifications-ionic-capacitor/
解决方法是先注册APNS token再注册FCM token。
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == "granted") {
// Register with Apple / Google to receive push via APNS/FCM
if(Capacitor.getPlatform() == 'ios'){
PushNotifications.register().then((res)=>{
console.log('From Regisiter Promise', res)
})
PushNotifications.addListener('registration', (token: Token)=>{
FCM.getToken().then((result) => {
this.remoteToken = result.token;
}).catch((err) => console.log('i am Error' , err));
})
}else{
FCM.getToken().then((result) => {
this.remoteToken = result.token;
}).catch((err) => console.log('i am Error' , err));
}
} else {
// No permission for push granted
alert('No Permission for Notifications!')
}
});
插件的最新版本:
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == "granted") {
PushNotifications.addListener('registration', async ({ value }) => {
let token = value // Push token for Android
// Get FCM token instead the APN one returned by Capacitor
if (Capacitor.getPlatform() === 'ios') {
const { token: fcm_token } = await FCM.getToken()
token = fcm_token
}
// Work with FCM_TOKEN
console.log(token);
})
} else {
// No permission for push granted
alert('No Permission for Notifications!')
}
});
使用 CAPACITOR
和 IONIC
在 Android 上一切正常,但在 IOS 上出现以下错误:
APNS device token not set before retrieving FCM Token for Sender ID 'mySenderId'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 3.2.2
@capacitor/core: 3.2.2
@capacitor/android: 3.2.2
@capacitor/ios: 3.2.2
Installed Dependencies:
@capacitor/cli: 3.2.2
@capacitor/core: 3.2.2
@capacitor/android: 3.2.2
@capacitor/ios: 3.2.2
我可以在我的 Xcode
日志中看到 FCM 令牌,但通知不起作用。
参考文献:
您似乎缺少 APNS 设置并将其与 FCM 连接。只需按照这个很棒的教程: https://devdactic.com/push-notifications-ionic-capacitor/
解决方法是先注册APNS token再注册FCM token。
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == "granted") {
// Register with Apple / Google to receive push via APNS/FCM
if(Capacitor.getPlatform() == 'ios'){
PushNotifications.register().then((res)=>{
console.log('From Regisiter Promise', res)
})
PushNotifications.addListener('registration', (token: Token)=>{
FCM.getToken().then((result) => {
this.remoteToken = result.token;
}).catch((err) => console.log('i am Error' , err));
})
}else{
FCM.getToken().then((result) => {
this.remoteToken = result.token;
}).catch((err) => console.log('i am Error' , err));
}
} else {
// No permission for push granted
alert('No Permission for Notifications!')
}
});
插件的最新版本:
PushNotifications.requestPermissions().then((permission) => {
if (permission.receive == "granted") {
PushNotifications.addListener('registration', async ({ value }) => {
let token = value // Push token for Android
// Get FCM token instead the APN one returned by Capacitor
if (Capacitor.getPlatform() === 'ios') {
const { token: fcm_token } = await FCM.getToken()
token = fcm_token
}
// Work with FCM_TOKEN
console.log(token);
})
} else {
// No permission for push granted
alert('No Permission for Notifications!')
}
});