IOS 打开 Url 在某些设备上不工作

IOS Open Url not working on some devices

@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.")
        }
}

我的项目中有这段代码。当我测试它时,它完美无缺地工作。但出于某种原因,它适用于我的 phone 而不是我的测试设备。任何人都可以解释发生了什么吗?

Self.currentUser.linkedin = https://nl.linkedin.com/in/username

当我点击 phone 上的按钮时它不起作用,我没有从 canOpenUrl()

收到任何错误

这是一个错误吗?

感谢任何遮阳篷!

塞斯

我发现了问题。在测试设备上,safari 被禁用。打开 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()
}

如果它无声地失败,则此错误消息将提示并放入一个文本字段中,其中包含 link。这样用户就可以将其复制并粘贴到浏览器中。

我希望它对其他人也有帮助!

塞斯