gpt4 book ai didi

ios - didReceiveRemoteNotification 在单击通知(背景)时不工作,但在应用程序为前台时工作

转载 作者:行者123 更新时间:2023-12-01 16:12:55 26 4
gpt4 key购买 nike

需要一些关于 PUSH Notifications 的解决方案。我从堆栈中尝试了不同的解决方案,但对我不起作用!

我的问题是当我从我的 触发通知时PHP 脚本 通知本身被触发。单击我想从我的应用程序导航到新 View 的通知的事情。

当应用程序在 中时后台模式并且单击通知对 没有任何作用完成处理程序警告 ,但当应用程序位于 事件状态并触发通知完成工作并导航到另一个 View
请恢复此问题,我附上了下面的代码。

在后台模式下单击通知时出错
警告:UNUserNotificationCenter 委托(delegate)收到了对 -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: 的调用,但从未调用过完成处理程序。

任何帮助表示赞赏

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],

fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,

let application = UIApplication.shared
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "LaunchScreenViewController")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

if let messageID = userInfo[gcmMessageIDKey] {

print("Message ID: \(messageID)")

}

// Print full message.

print(userInfo)

print("Hello u have entered through Push notification ")

completionHandler(UIBackgroundFetchResult.newData)
}

最佳答案

您好,我刚刚得到了答案的解决方案!
我尝试导航到 中的另一个 View usernotificationcenter 扩展方法它奏效了。

extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Entry through the Notification")

let application = UIApplication.shared
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "stationListVC")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()

if response.actionIdentifier == "remindLater" {
let newDate = Date(timeInterval: 900, since: Date())
scheduleNotification(at: newDate)
}
}
}

感谢大家的帮助;)

关于ios - didReceiveRemoteNotification 在单击通知(背景)时不工作,但在应用程序为前台时工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60224502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com