You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS推送通知用户点击允许仍被静默拒绝的问题求助

iOS推送通知用户点击允许仍被静默拒绝的问题求助

我最近在给Capacitor开发的iOS应用集成推送通知,遇到了一个特别诡异的问题:启动应用时会正常弹出权限请求弹窗,我明明点击了「允许」,但控制台日志却显示推送权限被拒绝了,完全摸不着头脑😫

先贴出我处理推送权限和FCM注册的核心代码:

constructor( private pushNotificationService: PushNotificationService ) {
  this.platform.ready().then(() => {
    this.requestLocalNotificationPermission();
    console.log('🚀 Platform ready');
    this.initPushNotifications();
  });
}

initPushNotifications() {
  console.log('🔍 Requesting push permission...');
  PushNotifications.requestPermissions().then(result => {
    console.log('🛂 Permission result:', result);
    if (result.receive === 'granted') {
      console.log('✅ Permission granted. Registering for notifications...');
      PushNotifications.register();
      
      // 📥 注册后新增的手动获取FCM Token逻辑
      FirebaseMessaging.getToken().then(result => {
        console.log('🎯 Firebase Token (manual):', result.token);
        alert('Manual FCM Token:\n' + result.token);
      }).catch(err => {
        console.error('❌ Error getting FCM token manually:', err);
      });
    } else {
      console.warn('⛔ Push permission not granted.');
    }
  });

  console.log('📡 Setting up push notification listeners...');
  PushNotifications.addListener('registration', (token: Token) => {
    console.log('✅ Device registered for push notifications!');
    console.log('📱 FCM Token:', token.value);
    alert('FCM Token:\n' + token.value);
  });

  PushNotifications.addListener('registrationError', err => {
    console.error('❌ Error registering for push notifications:', err);
  });

  PushNotifications.addListener('pushNotificationReceived', (notification: PushNotificationSchema) => {
    console.log('📥 Push notification received in foreground:', notification);
  });

  PushNotifications.addListener('pushNotificationActionPerformed', (action: ActionPerformed) => {
    console.log('🔍 Notification action performed:', action);
  });
}

下面是Xcode控制台里和问题直接相关的日志片段:

⚡️ To Native -> PushNotifications requestPermissions 84505968
⚡️ [log] - 🚀 Platform ready
⚡️ [log] - 🔍 Requesting push permission...
⚡️ [log] - 📡 Setting up push notification listeners...
⚡️ TO JS {"receive":"denied"}
⚡️ [log] - 🛂 Permission result: {"receive":"denied"}
⚡️ [warn] - ⛔ Push permission not granted.
⚡️ TO JS {"display":"granted"}
⚡️ [log] - Local notifications permission granted

可以看到本地通知的权限正常被授予了,但推送通知权限明明我点击了允许,却返回了denied。我对照文档检查了Info.plist和FCM的配置,看起来都是符合要求的,但就是卡在这里。

有没有朋友遇到过类似的问题?或者能帮我指几个排查方向?


内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 10:44:32