在 info.plist 文件中,我配置URL Identifier并URL Scheme成功。我也可以使用自定义 URL 打开应用程序。问题是当应用程序第一次启动该方法时
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
Run Code Online (Sandbox Code Playgroud)
不叫。
我有一些基于上述方法的依赖功能。所以当应用程序第一次启动时,我在我的应用程序中看不到任何东西。
我还在方法中添加了代码
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
let url = connectionOptions.urlContexts.first?.url
}
Run Code Online (Sandbox Code Playgroud)
但我在这里得到的 url 为零。
但是,如果我的应用程序处于后台模式并且我点击了 URL,那么上述方法调用成功并且相关功能正常工作。以下是我scene(_:openURLContexts:)在sceneDelegate.
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>){
let url = URLContexts.first?.url
let urlString: String = url!.absoluteString
if let urlComponents = URLComponents(string: urlString),let queryItems …Run Code Online (Sandbox Code Playgroud) 即时实现深层链接是iOS。我已经在 Project-Setting->Info->Url type URL Schemes 中配置了 URL Schemes : carwash role:Viewer
当我输入 carwash://something 时,浏览器要求打开应用程序,但在应用程序中没有调用我处理应该发生的操作。
苹果文档说你应该在 AppDelegate 中覆盖 application(open url) 但深层链接不调用它并且应用程序在最后状态打开
application:openURL:options:' 未被调用
这是我的代码并且不起作用
func application(_ app: UIApplication, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
fatalError()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if let url = launchOptions?[UIApplication.LaunchOptionsKey.url] as? URL {
/// some
fatalError()
}
GMSServices.provideAPIKey("")
return true
}
Run Code Online (Sandbox Code Playgroud)
swift 5 模拟器:iOS 13
我在我的 Xcode 项目中添加了一个自定义 URL 方案(我使用的是 SwiftUI)。
在 AppDelagate 文件中,我添加了:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print(url.absoluteString)
print("work")
return true
}
Run Code Online (Sandbox Code Playgroud)
当我在模拟器或物理设备中访问 Safari (sampleurlscheme://) 时,代码没有被执行(即日志不显示等),但它把我带到了应用程序。
有什么我遗漏的或者这可能是一个错误吗?
大家好 - 我是这里的新手......试图让我的第一个 iOS Swift (Xcode 11.2.1 / Swift 5 / iOS 13.2) 应用程序通过 URL 打开并处理 URL 字符串。应用程序打开得很好,但函数(方法?)似乎没有被调用。这是我所拥有的:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("Here I iz ... in the URL responding bit.")
print(url)
return true
}
...
Run Code Online (Sandbox Code Playgroud)
该代码位于我项目的AppDelegate.swift文件中。
这就是我在Info.plist文件中的内容。
我在设备上和模拟器中通过 Safari 启动 confirmevent://HelloWorld
正如我所说......应用程序正在打开,但我在 Xcode 调试区域中没有看到我的打印语句的任何结果。
在搜索其他帖子时,他们说我需要使用“等待可执行文件启动”将 Xcode 附加到应用程序,我已经完成并且确实附加了。 但是我注意到,当我通过“等待可执行文件启动”选项打开时,我在应用程序中散布的数十个打印语句中没有一个出现。
任何/所有帮助将不胜感激。我花了超过 …
我想用我的应用程序打开 zip 文件并配置以下内容:
这导致我的应用程序在其他应用程序的共享表中出现。但是当我在该共享表中点击我的应用程序时,我的应用程序被打开,但我的 AppDelegate 中的以下方法从未被调用:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
Run Code Online (Sandbox Code Playgroud)
这是一个 iOS 13 应用程序 - 我在这里错过了什么?
swift ×4
ios ×2
ios13 ×2
swift5 ×2
debugging ×1
deep-linking ×1
iphone ×1
swiftui ×1
url-scheme ×1
xcode ×1