gpt4 book ai didi

swift - UIApplication.shared.open(_ url : URL, etc.) 没有打开任何东西

转载 作者:行者123 更新时间:2023-11-28 07:37:44 25 4
gpt4 key购买 nike

我已将“instagram”添加到 Info.plist 文件中的 LSApplicationQueriesSchemes,但在调用以下函数时它仍然无法打开 safari 和 instagram:

func openinstagram () {
let instaurl = URL(fileURLWithPath: "https://www.instagram.com/(myusername)/?hl=de")
if UIApplication.shared.canOpenURL(instaurl) {
UIApplication.shared.open(instaurl, options: [:] ) { (sucess) in
print("url opened")
}
}
}

除了日志中的“url opened”,它什么也没告诉我

解决这个问题的方法是什么?提前谢谢你

最佳答案

你可以试试这个。

URL(fileURLWithPath:) 用于获取以/开头的文件

URL(string:) 是创建网址

func openinstagram () {
if let instaurl = URL(string: "https://www.instagram.com/(myusername)/?hl=de"),
UIApplication.shared.canOpenURL(instaurl) {

if #available(iOS 10.0, *) {
UIApplication.shared.open(instaurl)
} else {
UIApplication.shared.openURL(instaurl)
}
}
}

关于swift - UIApplication.shared.open(_ url : URL, etc.) 没有打开任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52983673/

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