MKAnnotation:单击 MKAnnotation 信息视图中的文本应该拨打一个号码

发布于 2024-08-12 17:34:29 字数 106 浏览 4 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不羁少年 2024-08-19 17:34:29

其工作方式是:您提供一个“tel:”URL 供您的应用程序打开。这将调用“电话”应用程序,该应用程序会自动开始拨打提供的号码。要通过单击注释标注来执行此操作,您需要在 MKMapViewDelegate 中提供 mapView:annotationView:calloutAccessoryControlTapped: 方法。

例如,如果您要拨打的电话是注释的标题,那么您将这样做:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    NSString *phoneNo = view.annotation.title;
    NSString *telString = [NSString stringWithFormat:@"tel:%@", phoneNo];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
}

实际上,您还需要检查当前设备是否确实是电话(即不是 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 your MKMapViewDelegate.

If, for example, the phone that you wish to dial is the annotation's title, this is how you'd do it:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    NSString *phoneNo = view.annotation.title;
    NSString *telString = [NSString stringWithFormat:@"tel:%@", phoneNo];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文