繁体   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