Swift:应用程序(_:打开URL:选项::)根本没有被调用
我正在尝试通过我构建的另一个应用程序打开一个应用程序中的辅助视图控制器(不是初始)。因此,我试图将不是最初的视图控制器的链接,但根本没有调用该功能。
我已经实现了openurlcontexts
:
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts)
}
未被调用:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print(url)
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true)
let host = urlComponents?.host ?? ""
print(host)
if host == "accessPage" {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "jsonVC") as? JSONViewController
window?.rootViewController = vc
}
return true
}
我添加了所有info.plist
东西,并确保willfinishlaunchingwithoptions
didfinishishlaunchingwithingwithoptions
都返回true。
每当我从第一个应用程序打开第二个应用程序时,主视图控制器始终是要显示的应用程序,而不是我想要的一个应用程序,它是jsonviewController
。
这是第一个应用程序中的代码:
import UIKit
class ViewController: UIViewController {
@IBAction func accessButtonPressed(_ sender: UIButton) {
let application = UIApplication.shared
let secondAppPath = "second://accessPage"
guard let appURL = URL(string: secondAppPath) else { return }
if application.canOpenURL(appURL) {
application.open(appURL, options: [:], completionHandler: nil)
}
}
}
I'm trying to open a secondary view controller (not initial) in one app from a different app I built. So I'm trying to deep link to a view controller that's not the initial one, but the function is not being called at all.
I already implemented openURLContexts
:
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts)
}
Not being called:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print(url)
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true)
let host = urlComponents?.host ?? ""
print(host)
if host == "accessPage" {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "jsonVC") as? JSONViewController
window?.rootViewController = vc
}
return true
}
I added all the info.plist
stuff and made sure willFinishLaunchingWithOptions
and didFinishLaunchingWithOptions
both return true.
Whenever I open the second app from the first one the primary view controller is always the one being displayed, not the one I want which is the JSONViewController
.
Here's the code from the first app:
import UIKit
class ViewController: UIViewController {
@IBAction func accessButtonPressed(_ sender: UIButton) {
let application = UIApplication.shared
let secondAppPath = "second://accessPage"
guard let appURL = URL(string: secondAppPath) else { return }
if application.canOpenURL(appURL) {
application.open(appURL, options: [:], completionHandler: nil)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
评论
SceneDelegate
文件和删除applicationsCeneManifest
在info.plist.plist
,重新启动Xcode中,它的工作正常。Commented out the
SceneDelegate
file and deletedApplicationSceneManifest
in theinfo.plist
, restarted Xcode and it worked just fine.