开发者

Application exit when trying to call when no sim card exists

I am using tel:%@ to call from my application. when there is no sim c开发者_如何转开发ard in the device.The application exists showing no sim card installed alert. I don't want my application to exit,how to handle that. I found in one of the answers to set exit(0); in - (void)applicationWillResignActive:(UIApplication *)application . But its not working for me.


Try calling UIApplication canOpenURL: to determine whether opening the URL will work. This will return NO if you are on a device that doesn't support making calls (e.g., iPad or iPod Touch). It may also return NO if there is no SIM card installed.


If you don't want the app to exit, you have to use a UIWebView to invoke your call. This could be an example:

UIWebView *callWebview = [[UIWebView alloc] init];

NSString *phoneNumber = [[NSString stringWithString:@"tel:123456789"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];        
NSURL *phoneURL = [NSURL URLWithString:phoneNumber];
[callWebview loadRequest:[NSURLRequest requestWithURL:phoneURL]];

I use stringByAddingPercentEscapesUsingEncoding just in case I include some special characters I want to parse.

If you don't have a SIM installed, it will just return to the same view in which was invoked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜