簡體   English   中英

快速單擊UILabel時出現空白屏幕

[英]blank screen appears when click on UILabel in swift

我試圖通過單擊UIlabel快速打開具有選定號碼的iPhone呼叫屏幕。

黑屏出現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)

功能標簽

func labelPressed() {      

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

UIApplication.sharedApplication().openURL(url)

}

我的代碼有什么錯誤或缺失。 我嘗試在iPhone設備上運行。

快速使用

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

代替

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

您可以嘗試使用GCD的dispatch_async調用“ openURL”方法:

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

您應該從uri中省略//,即

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM