2015-10-10 58 views
0

我试图在swift中超链接的UIlabel上单击打开带有所选号码的iPhone调用屏幕。在swift中单击UILabel时会出现空白屏幕

一个空白屏幕出现1秒钟后即可。不出现iPhone呼叫屏幕。不知道我的代码中有什么问题。在viewDidLoad中

代码

let strPhone = "080 2854 2105" 

let attributedPhoneStr = NSMutableAttributedString(string:strPhone, attributes:[NSLinkAttributeName: NSURL(string: "http://aerospace.honeywell.com")!]) 

lblPhoneContact.attributedText = attributedPhoneStr 

lblPhoneContact.userInteractionEnabled = true 

let gestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("labelPressed")) 

lblPhoneContact.addGestureRecognizer(gestureRecognizer) 

功能labelPressed

func labelPressed() {  

let url:NSURL = NSURL(string: "tel://08028542105")! 

UIApplication.sharedApplication().openURL(url) 

} 

什么是错的还是我的代码失踪。 我试着在我的iPhone设备上运行。

回答

0

为SWIFT使用

let url:NSURL = NSURL(string: "telprompt:08028542105")! 

,而不是

let url:NSURL = NSURL(string: "tel://08028542105")! 
+0

不。使用“telprompt://”将调用请求调用,但是使用“tel://”将直接调用该号码而不提示请求。 –

0

你可以尝试使用GCD的dispatch_async调用 “的OpenURL” 的方法:

dispatch_async(dispatch_get_main_queue()) {() -> Void in 
    UIApplication.sharedApplication().openURL(url) 
} 
0

你应该忽略//从uri--也就是说它应该是

let url:NSURL = NSURL(string: "tel:08028542105")!