iPhone SDK:启动一个应用程序后,通话结束
-
22-09-2019 - |
题
我怎么会让一个电话从一个程序,或者启动程序后,立即呼吁结束?我知道这是可能的,因为某些应用程序在应用中的商店都已经这样做。
解决方案
我从苹果网站上的这个代码,它完美的作品:
-(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];
}
}
其他提示
我认为有两份这个
- 应用程序已在运行,而用户接收到一个提示,表明一个电话进来,并要求接受或拒绝
- 用户收到一个电话,但是该应用程序是没有运行
在第一种情况下,您的 UIApplicationDelegate 将收到消息 application:willChangeStatusBarFrame:
, application:didChangeStatusBarFrame:
, applicationWillResignActive:
, , applicationDidBecomeActive:
所有可能多次所有根据,如果用户选择接听电话或不可能 applicationWillTerminate:
如果他们选择离开你的应用,或没有。你也可以观察到这些事件的使用 NSNotificationCenter 从一类,是不是登记为应委托,请参阅"通知"部分 通过 类引用的详细信息。
在第二种情况下,我不知道那里是走官方SDK启你的应用程序时,一个电话结束。你能提供一个列表中的应用程序这样做?
编辑:
我想我明白你的意思是现在。你应该按照建议,从@jessecurry, openURL
上 UIApplication
与 tel:
协议将使一个电话。作为他们的权利要求的"这样做不可能的",而不是退出应用程序时的电话呼叫,我不知道他们怎么做因为我没有写信。他们可以使用一个外部VOIP服务等,或只是装的 tel:
URL内部一个看不见的websheet.不我可以评论,因为我还没有尝试过。
它是通过使用telprompt代替电话来完成。请看下面的代码
[[UIApplication的sharedApplication] 的OpenURL:[NSURL URLWithString:@ “telprompt:18004912200”]];
如果你想拨打电话从你的应用程序中,你可以使用一个tel:
网址。
下面是占用一个电话号码作为一个字符串和发起呼叫的方法。
- (void)dialNumber: (NSString*)telNumber
{
// fix telNumber NSString
NSArray* telComponents = [telNumber componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
telNumber = [telComponents componentsJoinedByString: @""];
NSString* urlString = [NSString stringWithFormat: @"tel:%@", telNumber];
NSURL* telURL = [NSURL URLWithString: urlString];
//NSLog( @"Attempting to dial %@ with urlString: %@ and URL: %@", telNumber, urlString, telURL );
if ( [[UIApplication sharedApplication] canOpenURL: telURL] )
{
[[UIApplication sharedApplication] openURL: telURL];
}
else
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Dialer Error", @"" )
message: [NSString stringWithFormat: NSLocalizedString( @"There was a problem dialing %@.", @"" ), telNumber]
delegate: nil
cancelButtonTitle: NSLocalizedString( @"OK", @"" )
otherButtonTitles: nil];
[alert show];
[alert release];
}
}