You need to enable JavaScript to run this app. iOS推送点击跳转指定VC时AppDelegate通知回调仅前台执行
优惠活动
大模型
产品
解决方案
定价
更多

iOS推送点击跳转指定VC时AppDelegate通知回调仅前台执行

AppDelegate 通知方法触发异常、无法实现通知点击跳转的问题

当前存在的问题

  • AppDelegate 中的通知相关方法,仅在App已处于前台打开状态时,才会被通知事件触发
  • 预期实现效果:用户点击推送通知时,可直接跳转至App内的指定视图控制器
  • 异常表现:App处于后台状态时,用户点击通知唤起App的过程中,所有已实现的通知相关回调方法均未被调用

现有实现代码

AppDelegate 中当前的启动流程与通知配置代码如下:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
        if let error = error {
            print(error.localizedDescription)
        } else {
            application.registerForRemoteNotifications()
        }
    }
    
    UNUserNotificationCenter.current().delegate = self
    return true
}

已实现但触发无响应的回调方法如下:

// App处于前台时收到通知的展示权限回调
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler([.alert, .sound, .badge])
}

// 用户点击通知后的交互回调
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}

// 远程通知的后台拉取回调
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.22 15:45:07