アプリ内から電話をかけたり、通話が終了した直後にアプリを起動したりするにはどうすればよいですか?アプリストアの一部のアプリがすでにこれを行っているため、これが可能であることを私は知っています。
4 に答える
このコードはAppleサイトから入手しましたが、完全に機能します。
-(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];
}
}
これには2つの部分があると思います
- アプリケーションはすでに実行されており、ユーザーは電話がかかってきたことを示すプロンプトを受け取り、受け入れるか拒否するかを尋ねられます
- ユーザーは電話を受けましたが、アプリケーションが実行されていません
最初のケースでは、UIApplicationDelegateはメッセージ、、、およびすべてを複数回受信するapplication:willChangeStatusBarFrame:
可能性があります。これは、ユーザーが電話に出るかどうか、場合によってはアプリケーションを離れるかどうかによって異なります。アプリケーションデリゲートとして登録されていないクラスからNSNotificationCenterを使用してこれらのイベントを監視することもできます。詳細については、 UIApplicationクラスリファレンスの「通知」セクションを参照してください。application:didChangeStatusBarFrame:
applicationWillResignActive:
applicationDidBecomeActive:
applicationWillTerminate:
2番目のケースでは、通話が終了したときにアプリケーションを起動するための公式SDKがないかどうかはわかりません。これを行うアプリケーションのリストを提供していただけますか?
編集:
私はあなたが今何を意味するのか理解していると思います。@jessecurryからのアドバイスに従う必要があります。プロトコルを使用openURL
するUIApplication
とtel:
、電話がかけられます。「不可能なことをする」という彼らの主張と、電話がかかってきたときにアプリをやめないということについては、私が書いていなかったので、彼らがどのようにそれをしたのかわかりません。Skypeなどの外部VOIPサービスを使用しているか、非tel:
表示のWebシート内にURLをロードしている可能性があります。まだ試したことがないので、どちらもコメントできません。
これは、telの代わりにtelpromptを使用して行われます。次のコードを見てください
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@ "telprompt:18004912200"]];
アプリ内から電話をかけたい場合は、tel:
URLを使用できます。
これは、電話番号を文字列として受け取り、通話を開始する方法です。
- (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];
}
}