简体   繁体   English

快速单击UILabel时出现空白屏幕

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

i'm trying to open iPhone call screen with selected number when click on UIlabel which is hyperlink in swift. 我试图通过单击UIlabel快速打开具有选定号码的iPhone呼叫屏幕。

a blank screen appears for 1 second and goes. 黑屏出现1秒钟,然后消失。 No iPhone call screen appears. 没有出现iPhone通话屏幕。 Don't know what is wrong in my code. 不知道我的代码出了什么问题。

Code in viewDidLoad 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)

Function labelPressed 功能标签

func labelPressed() {      

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

UIApplication.sharedApplication().openURL(url)

}

what is wrong or missing in my code. 我的代码有什么错误或缺失。 I tried running on my iPhone device. 我尝试在iPhone设备上运行。

for swift use 快速使用

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

instead of 代替

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

You can try to use the GCD's dispatch_async to invoke the "openURL" method: 您可以尝试使用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