2015-10-10 55 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")!