在 App.swift 文件中的何处放置应用程序委托代码?
Where to place app delegate code in App.swift file?
我正在尝试让 Snapkit 与 SwiftUI 一起工作以允许通过 SnapChat 登录。我正在关注这个 Whosebug 问题 (),但我无法让公认的解决方案发挥作用。作为答案发布的代码原本打算放在应用程序委托文件中,但从 XCode 的最新版本开始,它们已不再使用。相反,代码片段需要放在 AppName.swift 文件中,但我的断点不会触发。这是我的 App.swift 文件的当前版本:
import SwiftUI
import SCSDKLoginKit
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
let url = urlContext.url
var options: [UIApplication.OpenURLOptionsKey : Any] = [:]
options[.openInPlace] = urlContext.options.openInPlace
options[.sourceApplication] = urlContext.options.sourceApplication
options[.annotation] = urlContext.options.annotation
SCSDKLoginClient.application(UIApplication.shared, open: url, options: options)
}
}
非常感谢任何帮助。谢谢!
编辑:感谢 Asperi,这是有效的解决方案!在此处更新代码以防有人遇到此问题:
import SwiftUI
import SCSDKLoginKit
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
SCSDKLoginClient.application(UIApplication.shared, open: url)
}
}
}
}
你应该改用.onOpenURL
,比如
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
// .. do whatever needed here
}
}
}
}
我正在尝试让 Snapkit 与 SwiftUI 一起工作以允许通过 SnapChat 登录。我正在关注这个 Whosebug 问题 (
import SwiftUI
import SCSDKLoginKit
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
let url = urlContext.url
var options: [UIApplication.OpenURLOptionsKey : Any] = [:]
options[.openInPlace] = urlContext.options.openInPlace
options[.sourceApplication] = urlContext.options.sourceApplication
options[.annotation] = urlContext.options.annotation
SCSDKLoginClient.application(UIApplication.shared, open: url, options: options)
}
}
非常感谢任何帮助。谢谢!
编辑:感谢 Asperi,这是有效的解决方案!在此处更新代码以防有人遇到此问题:
import SwiftUI
import SCSDKLoginKit
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
SCSDKLoginClient.application(UIApplication.shared, open: url)
}
}
}
}
你应该改用.onOpenURL
,比如
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
// .. do whatever needed here
}
}
}
}