2014-10-01 89 views
0

我正在開發iphone應用程序,我有標籤的電話號碼,我需要撥打電話號碼從用戶觸摸。我嘗試了下面的代碼,但沒有打電話,我目前正在使用xcode模擬器進行檢查。通過編程從iphone應用程序撥打電話

我的代碼,

在我的頭文件

IBOutlet UILabel* lableMakeCall1; 

@property(nonatomic,retain) UIView* lableMakeCall1; 

我的.m文件包含

- (void)viewDidLoad 
{ 
lableMakeCall1.userInteractionEnabled = YES; 
    UITapGestureRecognizer *tapGesture1 = \ 
    [[UITapGestureRecognizer alloc] 
    initWithTarget:self action:@selector(didTapLabelWithGesture1:)]; 
    [lableMakeCall1 addGestureRecognizer:tapGesture1]; 
} 

- (void)didTapLabelWithGesture1:(UITapGestureRecognizer *)tapGesture1 { 
    NSString *phoneNumber = [@"tel://" stringByAppendingString:lableMakeCall1.text]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 

/* 
I tried in this code also 
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:lableMakeCall1.text]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];*/ 

} 
+0

另外,[spec說](https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html#//apple_ref/doc/uid/TP40007899-CH6-SW1)你使用'tel:',即沒有雙斜槓,但你必須在手機上測試,或者如果你使用'facetime:'鏈接,那麼你可以測試ann ipod/ipad – Petesh 2014-10-01 15:42:32

+0

還要確保有電話號碼中沒有空格。 – rmaddy 2014-10-01 16:03:03

回答

1

您需要測試這在iPhone上,你不能對來電iOS模擬器。您也無法在iPod Touch和iPad上撥打電話。