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

Flutter FCM远程推送IOS端失效 仅Android端正常 问题求助

FCM iOS端推送失效排查方案
  • APNs请求字段补全
    Firebase控制台发推送时会自动补齐iOS端所需的APNs专属配置,你自行发起推送的场景大概率是请求体缺失apns节点参数。iOS端可接收的FCM推送必须包含APNs相关配置,示例请求体结构如下:
{
  "token": "你的iOS设备FCM token",
  "notification": {
    "title": "推送标题",
    "body": "推送内容"
  },
  "apns": {
    "payload": {
      "aps": {
        "sound": "default",
        "content-available": 1
      }
    },
    "headers": {
      "apns-priority": "10"
    }
  }
}
  • FCM Token有效性校验
    先单独提取iOS端生成的FCM Token,通过接口工具直接调用FCM推送接口发测试请求,确认是token本身无效还是后端请求参数有误,注意iOS与Android的FCM Token不通用,不要混用两个端的token发推送。
  • 补全AppDelegate通知相关逻辑
    你当前的AppDelegate.swift仅完成了Firebase初始化,缺少iOS通知权限申请、APNs Token与FCM绑定的逻辑,需要补充代码,修改后的代码示例如下:
import UIKit
import Flutter
import Firebase
import UserNotifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    // 注册通知权限
    UNUserNotificationCenter.current().delegate = self
    let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
    UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions,
      completionHandler: { _, _ in }
    )
    application.registerForRemoteNotifications()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
  • 环境与配置校验
    确认Xcode中已开启Push Notifications、Background Modes下的Remote notifications选项;确认Firebase控制台上传的APNs .p8密钥未过期,Bundle ID、Team ID配置与Xcode项目完全一致;debug模式测试时不要强制指定推送为生产环境,release模式测试时不要指定为沙箱环境。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 14:54:07