在我的应用程序上触摸“推送”以移动屏幕。 如果应用程序已经在运行,它会很好地工作。 如果应用程序关闭并且您触摸该应用程序,您将无法接收信息。 如果通过触摸推送启动应用程序,有没有办法在等待我的应用程序主页完成加载后运行代码?
Appdelegate.swift
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
Execution code when touching push
}
触摸推送时的执行代码
在主页面加载之前执行,应用程序终止。
执行代码什么时候有办法等待触摸推送?
最佳答案
If the app is launched by touching the push, is there a way to run the code after waiting for the main page of my app to finish loading?
自己调用和触发这样的 didReceive
委托(delegate)方法是不可能的,或者说这不是理想的。
你可以用它来保存数据 messageID
或更好的是你的 userInfo
到你的本地,比如 UserDefaults
。然后当您的主屏幕或主屏幕或根屏幕已加载时,您自己检查它。如果 UserDefaults
包含推送数据,则从那里自行处理。否则,做正常的事情。
关于ios - 如果应用是通过触摸推送启动的,有没有办法等待应用的主页面完成加载后运行代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54283908/