在我的iOS应用程序中,我在SceneDelegate类中有以下函数:
func sceneWillEnterForeground(_ scene: UIScene) {
print("... sceneWillEnterForeground ALWAYS CALLED")
NotificationCenter.default.post(name: Notification.Name("update"), object: nil) // ONLY TO BE CALLED when universal link is not clicked
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
print("SCENE WITH UNIVERSAL LINK CLICK")
guard let url = userActivity.webpageURL else { return }
let userInfo: [String: String] = ["url": url.absoluteString]
NotificationCenter.default.post(name: NSNotification.Name("universalLink"), object: nil, userInfo: userInfo)
}
- sceneWillEnterForeground函数始终被调用
- scene(scene:continue:)仅在单击通用链接时调用。
- 我希望
NotificationCenter.default.post(name: Notification.Name("update"), object: nil)
仅在未单击通用链接时调用。
我尝试在sceneWillEnterForeground中从scene获取userActivity,但没有数据可用于添加任何条件检查。当未单击通用链接时,是否会调用任何其他函数?
1条答案
按热度按时间xvw2m8pv1#
我通过使用在scene(_:continue:)函数中设置的标志实现了所需的行为,然后检入sceneDidBecomeActive函数,该函数在应用程序返回前台后调用