gpt4 book ai didi

ios - Xcode 8 打开新的苹果 map

转载 作者:行者123 更新时间:2023-11-30 12:42:38 24 4
gpt4 key购买 nike

需要一些帮助。这是我的代码,当我单击 GoMap 按钮时,系统提示我此错误 fatal error :在解包可选值时意外发现 nil

@IBAction func GoMap(_ sender: UIButton) {   
UIApplication.shared.openURL(NSURL(string: "http://maps.apple.com/maps?saddr=1 Republic Boulevard , Singapore 038975")! as URL)

}

最佳答案

您的网址无效。空格需要转义为 %20:

URL(string: "http://maps.apple.com/maps?saddr=1%20Republic%20Boulevard,%20Singapore%20038975")!

或者,使用 URLComponent + URLQueryItem 让系统为您转义:

var components = URLComponents(string: "http://maps.apple.com/maps")!
components.queryItems = [URLQueryItem(name: "saddr", value: "1 Republic Boulevard, Singapore 038975")]
let url = components.url!
UIApplication.shared.openURL(url)

关于ios - Xcode 8 打开新的苹果 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42053395/

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