@IBAction func openLinkedin() {
let url = NSURL(string: self.currentUser.linkedin)!
if(UIApplication.sharedApplication().canOpenURL(url) == true){
if currentUser.linkedin.rangeOfString("linkedin") != nil{
UIApplication.sharedApplication().openURL(url)
}else{
Utility.sharedInstance.showAlert("\(currentUser.display_name) heeft geen correcte linkedin link.")
}
}else{
Utility.sharedInstance.showAlert("\(currentUser.display_name) heeft geen linkedin link ingevuld.")
}
}
我的项目中有这段代码。当我测试它时,它可以完美地工作。但是由于某种原因,它可以在我的手机上运行,而不在我的测试设备上运行。谁能解释发生了什么事?
Self.currentUser.linkedin = https://nl.linkedin.com/in/username
当我点击手机上不起作用的按钮时,canOpenUrl()没有出现任何错误
这是一个错误吗?
感谢您的遮阳篷!
塞斯
我发现了问题。在测试设备上没有使用野生动物园。打开URL的此提示无提示失败。我通过将其放在代码上方来修复它:
if(!UIApplication.sharedApplication().openURL(url)){
Utility.sharedInstance.showAlertL("Kan de link niet openen. Kopieer de onderstaande link en plak deze in de browser.", link: self.appDelegate.user.linkedin)
}
警报如下所示:
func showAlertL(message:String, link:String){
let responseAlert = UIAlertView()
responseAlert.alertViewStyle = UIAlertViewStyle.PlainTextInput
let tekstfield = responseAlert.textFieldAtIndex(0)
tekstfield?.text = link
responseAlert.title = "Opes!"
responseAlert.message = message
responseAlert.addButtonWithTitle("OK")
responseAlert.show()
}
如果它无提示地失败,则此错误消息将提示,并放入带有链接的文本字段中。这样,用户可以将其复制并粘贴到浏览器中。
我希望它也能帮助其他人!
塞斯
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句