微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在新的SwiftUIApp生命周期中处理SceneDelegate willConnectTo方法

如何解决如何在新的SwiftUIApp生命周期中处理SceneDelegate willConnectTo方法

如何在新的SwiftUI应用生命周期中处理此方法? 我正在查看场景,但没有有关SceneDelegate方法的任何信息

func scene(_ scene: UIScene,willConnectTo session: UIScenesession,options connectionoptions: UIScene.Connectionoptions) { method in SwiftUI new App cycle.

解决方法

使用.onReceive修饰符可以在设备收到特定通知时收到通知。 对于您的情况,您可以在其中一个视图的顶部使用.onReceive这样的通知来通知场景连接:

.onReceive(NotificationCenter.default.publisher(for: UIScene.willConnectNotification)) { notification in
                
            }
,

即使应用未运行且已从通知中启动,您也可以通过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()
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。