如何捕捉iPad拨打电话的错误得到错误“ iPhone通话不可用”

问题描述 投票:0回答:1

我对使用iPad拨打电话有疑问。我尝试拨打电话,但是iPad在系统上出现错误。如何控制此错误消息,如下图所示?如何捕获此错误?谢谢。

NSString *value = [NSString stringWithFormat:@"%@", phoneText];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",value]] options:@{} completionHandler:nil];

error messagee

ios objective-c swift phone-call openurl
1个回答
0
投票

在调用功能openURL:options:completionHandler:之前,您可以使用功能canOpenURL:。您可以找到reference here

在您的情况下,该函数将返回false,并且您可以提供备用。


NSString *value = [NSString stringWithFormat:@"%@", phoneText];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",value]];

if (url && [[UIApplication sharedApplication] canOpenURL: url]) {
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
} else {
    // your fallback - you can display an alert controller
}

© www.soinside.com 2019 - 2024. All rights reserved.