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

Flutter macOS端firebase_messaging报“通知不被允许”错误的解决方法

解决Flutter macOS应用Firebase推送通知权限问题
  • 检查Xcode权限声明与Capabilities配置

    1. 打开macOS/Runner.xcodeproj,在Info.plist中添加macOS推送必需的权限描述(10.14+版本要求):
      <key>NSUserNotificationUsageDescription</key>
      <string>用于接收重要消息提醒</string>
      <key>NSCriticalAlertUsageDescription</key>
      <string>紧急通知需要您的即时关注</string>
      
    2. 进入Xcode的Signing & Capabilities标签:
      • 添加Push Notifications capability;
      • 开启Background Modes下的Remote notifications选项。
  • 验证Firebase配置完整性

    1. 确认GoogleService-Info.plist已加入Bundle资源:在Xcode的Build Phases > Copy Bundle Resources中检查该文件是否存在,不存在则手动添加;
    2. 登录Firebase控制台,核对macOS应用的Bundle ID与Xcode中完全一致,并且已上传有效的APNs认证密钥(路径:Project Settings > Cloud Messaging > APNs Authentication Key)。
  • 调整权限请求代码
    macOS不支持carPlay、announcement这类iOS专属权限,先简化请求逻辑测试:

    final settings = await FirebaseMessaging.instance.requestPermission(
      sound: true,
      alert: true,
    );
    

    多余的不支持权限请求可能导致整体权限申请失败。

  • 重置系统权限缓存
    如果应用始终未出现在通知列表,通过终端命令重置通知权限:

    tccutil reset Notification com.your-app-bundle-id
    

    替换com.your-app-bundle-id为你的应用实际Bundle ID,之后重新运行应用。

  • TestFlight构建排查

    1. 归档构建时确保Push Notifications capability已正确启用,Info.plist权限描述完整;
    2. 通过TestFlight安装后,需手动启动应用,若未触发权限弹窗,可尝试卸载重装后再次打开。

内容的提问来源于stack exchange,提问作者FetFrumos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 07:52:52