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

iOS:didReceiveRemoteNotification仅在开发者模式设备后台生效问题求助

iOS 16/17中didReceiveRemoteNotification仅在开启开发者模式的后台触发问题

环境

  • iOS版本:16、17
  • 测试设备:iPhone 14 Pro(iOS 17.4)、iPhone 13 Pro(iOS 16.5.1及17.4)
  • Xcode及项目设置:已开启远程通知后台模式

预期行为

静默通知应触发didReceiveRemoteNotification函数,执行包括播放声音在内的操作,正常调用该函数处理通知。

实际行为

  • 开启开发者模式的设备(如iOS 17.4的iPhone 14 Pro、开启开发者模式后iOS 16.5.1的iPhone 13 Pro)可正确触发该函数;
  • 未开启开发者模式的iOS 17.4版iPhone 13无法触发,偶尔会调用applicationDidBecomeActive。

代码片段

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
    Logger.log(function: "didReceiveRemoteNotification", message:"application: \(application.debugDescription), userInfo: \(userInfo.debugDescription)")
    let notification = NotificationParser.from(userInfo: userInfo)

    guard notification.type.isEmpty == false else {
        Logger.log(function:"Notification Handler", message: "Notification type is empty")
        return .failed
    }

    NotificationService.handleNotification(userInfo: userInfo)
    return .newData
}

通知Payload

{
    "aps": {
        "content-available": 1
    },
    "id": "test",
    "action": "actionA",
    "body": "Sample body text to be used internally",
    "type": "typeA",
    "title": "Notification Title Example"
}

已尝试的排查步骤

  • 确保所有设备已开启后台应用刷新和通知权限
  • 确认项目后台模式配置正确
  • 尝试使用带完成参数或异步返回的didReceiveRemoteNotification版本

问题求助

是否有人遇到过该问题?求问问题原因及解决建议。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 22:25:05