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

iOS 15.5中前台远程通知不显示问题求助

iOS 15.5前台远程通知不显示的排查方案

针对后台能正常接收通知、前台无法显示的问题,可按以下步骤逐一排查:

  • 确认协议遵守状态
    确保你的AppDelegate类已正确声明遵循UNUserNotificationCenterDelegate协议:

    class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
        // ... 其他业务代码
    }
    
  • 检查通知权限请求配置
    iOS 15+前台显示通知依赖.alert权限,需确认请求权限时包含该选项:

    // 在application didFinishLaunchingWithOptions中补充权限请求代码
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
        if granted {
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
    
  • 验证Delegate绑定有效性
    确保UNUserNotificationCenter.current().delegate = self在权限请求前执行,且后续无其他代码替换delegate实例(比如某ViewController中重新设置了delegate)。

  • 检查远程通知Payload格式
    推送的payload必须包含alert字段,否则前台不会显示banner:

    {
        "aps": {
            "alert": {
                "title": "测试标题",
                "body": "测试内容"
            },
            "sound": "default",
            "badge": 1
        }
    }
    
  • 确认willPresent方法触发状态
    在userNotificationCenter(_:willPresent:withCompletionHandler:)方法中添加日志或断点,验证方法是否被调用。若未触发,说明delegate未正确绑定。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 19:36:18