在iPhone上拨打电话并将用户带回应用程序? (UIWebView做到了) [英] Make phone call on iPhone and take user back to app? (UIWebView does it)

查看:133
本文介绍了在iPhone上拨打电话并将用户带回应用程序? (UIWebView做到了)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码拨打电话:

I used this code to make phone call:

NSString *phoneNumber = [@"tel://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

当通话结束时,它不会将用户带回应用程序。但是,如果我在UIWebView中显示一个网站,并且网站上有一个电话号码(即UIWebView识别它),如果我点击该电话号码链接拨打电话,我将在电话结束时被带回应用程序。

and when the call ends, it does not take user back to the app. However, if I show a website in UIWebView and there is a phone number in the website(ie UIWebView recognises it), and if I tap that phone number link to make phone call, I will be taken back to the app when the call finishes.

我的初步想法是,UIWebView在内部执行某些操作,例如指向电话应用程序的深层链接,然后深层链接中的另一个深层链接,将用户带回应用程序。但我不确定。有没有办法实现这个功能?

My preliminary thinking is that the UIWebView does something internally like a deep link to the Phone app then another deep link inside the deep link to take the user back to the app. But I'm not sure. Is there a way to implement this feature?

谢谢!

推荐答案

您需要使用 telprompt URL,而不是 tel

You need to use the telprompt URL, not tel.

所以:

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

在拨打该号码之前,这也会给用户一个确认框。

This will also give the user a confirmation box before calling the number.

编辑:

这个问题涵盖了同样的问题。

This question covers the same issue.

编辑2:

对于那些想知道这个URL是否会导致App Store拒绝的人来说,答案通常是否定的。更大的风险是Apple会突然停止支持 telprompt 计划。正如这篇文章,用 UIWebView <实现 telprompt 有一种稍微安全的方式/ code>(在内部使用 telprompt ,即使你用 tel 调用它)。文章中的相关代码显示了如何使用记录的 tel 方案仍然可以为您提供 telprompt 的效果:

For those wondering if this URL will result in rejection from the App Store, the answer is generally no. The greater risk is that Apple will suddenly stop supporting the telprompt scheme. As explained by this article, there is a slightly 'safer' way of implementing telprompt with UIWebView (which uses telprompt internally, even if you call it with tel). The relevant code from the article shows how using the documented tel scheme can still give you the effect of telprompt:

+ (void)callWithString:(NSString *)phoneString {
    [self callWithURL:[NSURL URLWithString:[NSString     
        stringWithFormat:@"tel:%@",phoneString]]];
}

+ (void)callWithURL:(NSURL *)url {
    static UIWebView *webView = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{  
        webView = [UIWebView new];
    });
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
}

(代码取自第二次编辑中的文章参考)

(Code taken from the article reference in my second edit)

这篇关于在iPhone上拨打电话并将用户带回应用程序? (UIWebView做到了)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆