ios - iphone 7以下参数为零,但以上功能正常

标签 ios swift

同样的代码在iPhone 7以下的模拟器上运行无法正常取值,但在iPhone 7以上的模拟器上可以运行。

使该行崩溃:

connet(str: "https://a_web?code=\(code!)")   

错误消息:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Option

我确信它指定了这个参数代码。 VC1 使用 segue 到 VC2。

VC1

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "loginS" {
        let employeeVC = segue.destination as! EmployeeVC
        employeeVC.code = self.code
    }
}

VC2

// Error on the following line:
connet(str: "https://a_web?code=\(code!)")   

func connet(str : String){
    if let url = URL(string: str) {
        let safariController = SFSafariViewController(url: url)
        present(safariController, animated: true, completion: nil)
    }
}

我该怎么做,才能让所有设备正常工作?

最佳答案

请尝试将 EmployeeVC 中的代码声明为

var code = ""

然后调用这样的方法

connet(str: "https://a_web?code=\(code)")  

并尝试将 VC 推为

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "loginS" {
        if let employeeVC = segue.destination as? EmployeeVC {
            employeeVC.code = self.code
        }

    }
}

如果代码是整数,则解析后将其作为字符串发送。 谢谢

关于ios - iphone 7以下参数为零,但以上功能正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55604421/

相关文章:

ios - 变量不存储?

ios - 使用正则表达式或其他机制在 NSAttributedString(或 NSString)中查找标签

ios - Facebook 与 Parse 无法登录 Swift 2.0

ios - swift 的图像模糊

swift - Swift 4 中的 KVO 监听器问题

ios - 无法在 Xcode Playgrounds 上运行 SAConfettiView

ios - Firebase iOS Google 登录——使用未声明的类型 GIDSignInDelegate

ios - 在 secondViewController 中有 4 个 textField 。我想用 firstviewController Collection View 单元检查这个 textField 值

swift - 触发一个事件并等待多个事件 RxTest

ios - 扩展中无法识别 Swift 类属性