2012-09-15 63 views
0

我有一個電話號碼作爲標題的UIButton。使用按鈕標題打開電話應用程序

此代碼是否會以標題編號打開手機應用程序?

- (IBAction)callContact:(id)sender 
{ 
    [[UIApplication sharedApplication] openURL: 
     [NSURL URLWithString:telfButton.titleLabel.text]]; 
} 

它給了我一個錯誤。

回答

0

取決於URL的內容。 如果它只是3033749943它將無法正常工作。但tel://3033749943將工作得很好。

0

正如在其他答案中所述,你必須使用「tel://」來啓動手機應用程序並撥打號碼。但是,您可以使用NSStringstringWithFormat在「tel://」之後的按鈕標題中添加數字。

- (IBAction)callContact:(id)sender 
{ 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",telfButton.titleLabel.text]]; 
} 
相關問題