gpt4 book ai didi

ios - 将地址 (UITextView) 连接到 Apple map

转载 作者:行者123 更新时间:2023-11-30 10:25:06 25 4
gpt4 key购买 nike

我正在尝试实现一些功能:

我想要一个 UITextView,它恰好是某个地方的地址,当用户点击此 UITextView 时引导用户到 Apple map ,并在 UITextView 中显示该地址的位置。关于我如何做到这一点有什么想法吗?

到目前为止我尝试过的事情:

import MapKit

@IBOutlet weak var firstAddressTapped: UITextView!

func viewDidLoad() {
let attributedString = NSMutableAttributedString(string: "The address of my place")
attributedString.addAttribute(.link, value: "http://maps.apple.com/?daddr=The+address+of+my+place", range: NSRange(location: 19, length: 55))
firstAddressTapped.attributedText = attributedString
}

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL)
return false
}

谢谢!

最佳答案

你可以这样传递地址;

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL)
// check if user touched the link.
if range == NSRange(location: 19, length: 55) {
UIApplication.sharedApplication().openURL(NSURL(string: "http://maps.apple.com/?address=The+address+of+my+place")!)
}
return false
}

关于ios - 将地址 (UITextView) 连接到 Apple map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60097134/

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