2012-07-11 77 views
0

可能重複:
How to make a call programmatically?如何在iphone中撥打電話?

在我的應用程序,我有一個觀點,其中有一家公司的電話號碼,完整地址被顯示出來。我想要的是,當用戶觸摸該電話號碼時,它應該撥打電話。 那麼,當用戶觸摸該電話號碼時如何操作。 任何答案將appriciated。感謝你們。

+1

試... [UIApplication的sharedApplication] openURL:[NSURL URLWithString:@「tel:91-775-107-1248」]]; – Dhiru 2016-11-09 11:20:40

回答

0

如果您將文本置於UITextView中,則會設置該設置以自動檢測電話號碼。然後,OS將突出的電話號碼,如果用戶點擊它,如果他們想打這個電話

+0

當用戶點擊該號碼時,是否可以在模擬器中看到提示消息。 – Tarunkumar 2012-07-11 13:22:13

+0

現在我在文本視圖中獲取該數據,但不能通過鼠標進行點擊。那麼如何知道它的工作與否呢? – Tarunkumar 2012-07-11 13:24:25

+0

我需要添加[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@「tel:9995551234」]]; – Tarunkumar 2012-07-11 13:25:48

0
-(IBAction)callPhone:(id)sender { 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:1234567890"]]; 
} 

然後連接TouchUpInside這個,你是好去它會提示他們。希望有所幫助!

0
-(void)callPhone:(id)sender{ 

    NSURL *url = [NSURL URLWithString: @"tel://848444488"]; 
    NSLog(@"Call %@", url); 
    [[UIApplication sharedApplication] openURL:url]; 

} 

如果手機是在形式848 44 44 88使用此代碼,以消除空間:

NSString *phoneWithoutSpaces = [[NSString stringWithFormat:@"tel://%@", @"848 44 44 88"] stringByReplacingOccurrencesOfString:@" " withString:@""]; 

NSURL *url = [NSURL URLWithString:phoneWithoutSpaces]; 
0

做這個

NSString *phoneNumber = [NSString StringWithFormat:@"tel:%@", textField.text]; 

[[UIApplication SharedApplication] openURL:[NSURL URLWithString:phoneNumber]];