簡體   English   中英

如何撥打電話並在之后返回原始應用程序

[英]How to make a phone call AND return to the original app afterwards

如果我使用UIWebView顯示電話號碼並將數據檢測器類型設置為UIDataDetectorTypePhoneNumber,那么當我點擊該號碼時,可以撥打電話。

電話結束后,我將返回我的應用程序

但是,如果我嘗試使用編程方式調用手機應用程序

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:123456789"]];

要么

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];

然后在通話結束后無法返回我的應用程序。

是否有可能以編程方式啟動手機應用程序,然后在通話結束后返回我的應用程序,就像用戶點擊UIWebView中的數字一樣?

代替:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];

采用:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://123456789"]];

telprompt:// vs. tel://

這將彈出警報視圖,用戶將必須點擊“呼叫”,但這會在呼叫完成后返回到應用程序。

不幸的是,Apple不允許這樣做,因為當你執行openURL命令時,它將打開該應用程序,並且由於你無法訪問該應用程序中的任何內容,因此你必須自己重新輸入你的應用程序。 但是,您可以在NSUserDefaults保存您的狀態,然后讓用戶能夠返回到應用程序的相同部分,就像他們離開時一樣。 點擊此處獲取幫助: iOS人機界面指南

例如用

NSString * telNummer;
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 5.0) { 
    telNummer = [NSString stringWithFormat: @"telprompt://%@", person.telephoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telNummer]];
} else {
    telNummer = [NSString stringWithFormat: @"tel://%@", person.telephoneNumber]; 
    UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:telNummer]]]; 
    webview.hidden = YES; 
    // Assume we are in a view controller and have access to self.view 
    [self.view addSubview:webview]; 
    [webview release];

}    

您可以在撥號應用程序對用戶可見2-3秒后發送本地通知。 它不是完美的,但點擊本地通知是回到原始應用程序,雙擊主頁按鈕和切換應用程序更容易。

NSURL * url = [NSURL URLWithString:@“telprompt://您的電話號碼”]; [[UIApplication sharedApplication] openURL:url];

這可能有用嗎?

UIWebView webView = [[UIWebView alloc] init]; 
NSURL *url = [NSURL URLWithString:@"tel:123456789"]; 
[webView loadRequest:[NSURLRequest requestWithURL:url]];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM