【发布时间】:2010-12-31 07:22:39
【问题描述】:
我正在使用 tel:%@ 从我的应用程序中调用。当设备中没有 sim 卡时。应用程序存在显示未安装 sim 卡警报。我不希望我的应用程序退出,如何处理。我在其中一个答案中找到了 set exit(0);在 - (void)applicationWillResignActive:(UIApplication *)application 。但它不适合我。
【问题讨论】:
我正在使用 tel:%@ 从我的应用程序中调用。当设备中没有 sim 卡时。应用程序存在显示未安装 sim 卡警报。我不希望我的应用程序退出,如何处理。我在其中一个答案中找到了 set exit(0);在 - (void)applicationWillResignActive:(UIApplication *)application 。但它不适合我。
【问题讨论】:
尝试调用UIApplication canOpenURL: 以确定打开 URL 是否有效。如果您使用的设备不支持拨打电话(例如 iPad 或 iPod Touch),这将返回 NO。如果没有安装 SIM 卡,它也可能返回NO。
【讨论】:
如果您不希望应用退出,则必须使用 UIWebView 来调用您的调用。这可能是一个例子:
UIWebView *callWebview = [[UIWebView alloc] init];
NSString *phoneNumber = [[NSString stringWithString:@"tel:123456789"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneURL = [NSURL URLWithString:phoneNumber];
[callWebview loadRequest:[NSURLRequest requestWithURL:phoneURL]];
我使用stringByAddingPercentEscapesUsingEncoding 以防我包含一些我想要解析的特殊字符。
如果您没有安装 SIM 卡,它只会返回到调用时的相同视图。
【讨论】: