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

关闭飞行模式后未收到iOS推送通知问题排查(Noticed Gem)

调试与解决Noticed Gem离线推送丢失问题

1. 修正apn.priority配置

你设置的apn.priority = '10'是立即发送优先级,APNs不会缓存这类通知——如果发送时设备处于飞行模式(离线),通知会被直接丢弃,不会等待设备上线。这正是你遇到的核心问题。

要让离线设备上线后收到通知,必须将优先级改为'5',同时显式配置过期时间(避免依赖默认值可能的偏差):

def ios_format(apn)
  apn.custom_payload = { universal_link: url }
  apn.alert = { title: title(recipient), body: message(recipient) }
  apn.sound = 'default'
  apn.priority = '5' # 允许APNs缓存通知,等待设备恢复在线
  apn.expiration = 30.days.to_i # 显式设置30天过期时间
end

2. 验证Noticed参数是否正确生效

开启Rails调试日志,检查发送给APNs的请求细节:

  • 在环境配置文件(如config/environments/production.rb)中设置:
    config.log_level = :debug
    
  • 发送测试通知后,查看日志中的APNs请求,确认priority和expiration参数是否与配置一致。

3. 调试Noticed推送流程

  • 用deliver_now!触发推送并捕获异常,排查发送阶段的问题:
    begin
      YourNotification.with(recipient: target_user).deliver_now!
    rescue => e
      Rails.logger.error "推送失败详情: #{e.message}"
    end
    
  • 如果使用deliver_later异步推送,检查Sidekiq/Resque等队列的日志,确认作业未失败或被延迟。

4. 确认设备令牌有效性

即使Apple控制台无丢弃记录,也可能存在令牌状态异常:

  • 在用户模型中添加令牌校验逻辑:
    def valid_apn_token?
      client = Noticed::DeliveryMethods::Apns.new.client
      response = client.validate_token(self.apn_token)
      response.success?
    end
    
  • 针对问题设备测试令牌状态,排除令牌过期或无效的情况。

5. 直接测试APNs缓存行为

绕过Noticed,用curl发送原始请求验证APNs的缓存逻辑:

curl -v -d '{
  "aps": {
    "alert": {"title": "离线测试", "body": "测试离线推送"},
    "sound": "default",
    "priority": 5,
    "expiration": '"$(date -v+30d +%s)"'
  },
  "universal_link": "你的通用链接"
}' \
-H "apns-topic: 你的Bundle ID" \
-H "authorization: bearer 你的APNs授权令牌" \
https://api.push.apple.com/3/device/目标设备令牌

发送后开启飞行模式,再关闭,检查设备是否收到通知,以此排除Noticed的适配问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 05:48:15