gpt4 book ai didi

ios - 获取深层链接 url iOS 中的参数值

转载 作者:搜寻专家 更新时间:2023-10-31 19:32:46 25 4
gpt4 key购买 nike

大家。我的问题是:如何从深层链接 URL 获取数据?我有两个应用程序,我想使用深层链接将数据从 app1 发送到 app2。我在 app1 上有一个按钮,可以单击并打开 app2,然后 app 2 将通过深层链接 URL 从 app1 获取数据。

这是我在 app1 中发送按钮的代码:

@IBAction func btnSend_Clicked(_ sender: Any) {
let text = self.txtInput.text?.replacingOccurrences(of: " ", with: "%20")
UIApplication.shared.open(URL(string: "myapp://?code=\(text!)")!, options: [:], completionHandler: nil)
}

那么,我如何从 app2 中的深度链接 url(代码参数)获取数据?

非常感谢您的帮助!!!!

最佳答案

您在 Appdelegate 中实现此代码:

 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
let items = (urlComponents?.queryItems)! as [NSURLQueryItem]
if (url.scheme == "myapp") {
var vcTitle = ""
if let _ = items.first, let propertyName = items.first?.name, let propertyValue = items.first?.value {
vcTitle = url.query!//"propertyName"
}
}
return false
}

关于ios - 获取深层链接 url iOS 中的参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44580871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com