[英]iOS 4.2 - Return to app after phone call
我可以使用以下方法在我的应用程序中成功发起电话:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];
但是,一旦电话终止,是否可以自动返回到应用程序? 看来这在iPhone OS 3.0下是不可能的,但是我希望现在可以在iOS 4.2下使用多任务处理(我无法找到有关iOS 4.2的此问题的任何信息)。
在此先感谢您的协助!
我知道这个问题已经很老了,但目前您可以使用telprompt://来做到这一点(至少在iOS 5上如此),例如:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://123456789"]];
iPhone将显示警报视图确认,并在通话结束时再次显示您的应用,而不是iPhone的通话应用。
我认为问题在于您仍在进行sharedApplication调用,并且根据其他线程,无需将Web视图添加为层次结构的一部分。
我获取了您的代码,对其进行了如下修改,并且效果很好:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@", phoneNumber];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
// The WebView needs to be retained otherwise it won't work.
if (!mCallWebview)
mCallWebview = [[UIWebView alloc] init];
[mCallWebview loadRequest:[NSURLRequest requestWithURL:phoneURL]];
通话后,您自己的应用程序将像以前一样运行。
自iOS 4.0推出以来,这绝对有可能。 解决此问题的最佳方法是使用UIWebView,在WebView中加载“ tel:0123456” URL,而不将其添加到视图层次结构中。 iOS将自动显示带有电话号码的警报,并要求用户通过按“呼叫”进行确认。
通话结束后,您的应用将自动恢复到前台。 在另一个线程中对此进行了详细说明: 通话后返回应用程序行为的本机代码与UIWebView不同
我已经在iPhone SDK中给出了以下答案:通话结束后启动应用程序我还将在此处发布代码。在这里,您可以在不关闭应用程序的情况下拨打电话。
-(IBAction) dialNumber:(id)sender{
NSString *aPhoneNo = [@"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
NSURL *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 3.1) {
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
} else {
// On 3.0 and below, dial as usual
[[UIApplication sharedApplication] openURL: url];
}
}
使用iOS 9.3.4,我尝试控制的所有技术都可以在通话后返回到调用应用程序。 这种行为最近改变了吗? 这个例子只是https://github.com/jatraiz/RZTelpromptExample的Swift简化版本:
class ViewController: UIViewController {
let phoneNumber = "7204790465"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func callWithTelPushed(sender: AnyObject) {
if let url = NSURL(string: "tel:" + self.phoneNumber) {
UIApplication.sharedApplication().openURL(url)
}
}
@IBAction func callWithTelpromptPushed(sender: AnyObject) {
if let url = NSURL(string: "telprompt:" + self.phoneNumber) {
UIApplication.sharedApplication().openURL(url)
}
}
@IBAction func callWithRZTelpromptPushed(sender: AnyObject) {
RZTelprompt.callWithString(self.phoneNumber)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.