MKAnnotation:单击 MKAnnotation 信息视图中的文本应该拨打一个号码
我使用 MKMapview 在我的本机 iPhone 应用程序中显示地图,并向地图视图添加两个标记。单击注释标记后,我希望显示一个电话号码,单击该电话号码应拨打该号码。
我该怎么做?
I am using a MKMapview to display a map in my native iPhone application and I add two markers to the map view. On clicking the annotation marker I want a phone number to be displayed and clicking on the phone number should make a call to that number.
How can I do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其工作方式是:您提供一个“tel:”URL 供您的应用程序打开。这将调用“电话”应用程序,该应用程序会自动开始拨打提供的号码。要通过单击注释标注来执行此操作,您需要在
MKMapViewDelegate
中提供mapView:annotationView:calloutAccessoryControlTapped:
方法。例如,如果您要拨打的电话是注释的标题,那么您将这样做:
实际上,您还需要检查当前设备是否确实是电话(即不是 iPod touch 或iPad)。在启动“电话”应用程序之前让用户知道他们即将拨打电话也很好。例如,向他们展示一个操作表,让他们决定是否拨打电话或取消。
The way this works is: you provide a "tel:" URL for your application to open. This calls the Phone application, which automatically starts dialling the provided number. To do this by clicking on an annotation callout, you need to provide a
mapView:annotationView:calloutAccessoryControlTapped:
method in yourMKMapViewDelegate
.If, for example, the phone that you wish to dial is the annotation's title, this is how you'd do it:
In practice, you would also need to check whether the current device is indeed a phone (i.e. not an iPod touch or an iPad). It would also be good to let the user know that they are about to make a phone call, prior to launching the Phone app. E.g. show them an action sheet that allows them to decide whether to make the call or cancel.