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

Flutter应用后台/终止状态下Live Activity无法更新问题求助

解决Flutter Live Activity后台/锁屏无法更新的问题

核心原因

Live Activity的更新依赖iOS专属的ActivityKit Push Notification(而非普通FCM通知),普通FCM消息无法触发Live Activity的状态更新,必须配置特定的推送格式和权限。

具体排查与修复步骤

1. 确认权限与配置

  • 在Info.plist中添加Live Activity及后台推送相关配置:
    <key>NSSupportsLiveActivities</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>remote-notification</string>
        <string>fetch</string>
    </array>
    
  • 在Xcode项目中开启Push Notifications能力,并在Background Modes中勾选Remote notifications

2. 发送符合要求的FCM推送

普通FCM消息无法触发Live Activity更新,必须发送包含apns字段的专属格式,示例:

{
  "message": {
    "token": "目标设备的FCM_TOKEN",
    "apns": {
      "payload": {
        "aps": {
          "alert": {},
          "sound": "",
          "liveActivity": {
            "event": "update",
            "contentState": {
              // 与你创建Live Activity时的状态结构一致,比如:
              "orderStatus": "配送中",
              "progress": 60
            },
            "staleDate": "2024-12-31T23:59:59Z"
          }
        }
      }
    }
  }
}
  • 注意:liveActivity.event只能是update或end,contentState结构必须和初始化Live Activity时匹配

3. Flutter端监听更新回调

以常用的activity_kit插件为例,确保正确监听更新事件:

ActivityKit().addActivityUpdateListener((activity) {
  // 处理更新后的状态,同步UI显示
  print("Live Activity更新:${activity.contentState}");
});

4. 检查设备端设置

  • 确认设备已允许应用的通知权限,且开启了Live Activity通知(设置→通知→你的应用→Live Activity)
  • 锁屏状态下,确保通知预览设置为「始终」(设置→通知→显示预览→始终)

5. 规避iOS后台限制

  • 不要频繁发送推送,避免被系统限流
  • staleDate不要设置过近,否则Live Activity会提前进入失效状态

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 01:19:51