如何在新的SwiftUI应用生命周期中处理此方法? 我正在查看场景,但没有有关SceneDelegate方法的任何信息
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { method in SwiftUI new App cycle.
答案 0 :(得分:0)
使用.onReceive
修饰符可以在设备收到特定通知时收到通知。
对于您的情况,您可以在其中一个视图的顶部使用.onReceive
这样的通知来通知场景连接:
.onReceive(NotificationCenter.default.publisher(for: UIScene.willConnectNotification)) { notification in
}
答案 1 :(得分:0)
即使应用未运行且已从通知中启动,您也可以通过userNotificationCenter
接收通知。
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
print("open notification")
let userInfo = response.notification.request.content.userInfo
print(userInfo)
completionHandler()
}