如何在新的SwiftUI应用生命周期中处理此方法?我正在看这个场景,但是它没有任何关于SceneDelegate方法的信息。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { method in SwiftUI new App cycle.
发布于 2020-08-31 07:33:02
当设备收到特定通知时,可以使用.onReceive修饰符通知。对于您的情况,您可以在视图的顶部使用这样的.onReceive来获得场景连接的通知:
.onReceive(NotificationCenter.default.publisher(for: UIScene.willConnectNotification)) { notification in
}发布于 2020-11-18 03:13:17
即使应用程序没有运行并且是从通知启动的,您也可以通过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()
}https://stackoverflow.com/questions/63666287
复制相似问题