我在AppDelegate中的变量有问题

时间:2019-06-26 06:39:54

标签: swift sinch

当我尝试将App委托中的变量返回到viewController时,我的代码中出现错误,它返回空值,因此未分配委托。

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var client: SINClient!
.
.
.
}

class ViewController: UIViewController, SINCallClientDelegate {

    @IBOutlet weak var destination: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    func client() -> SINClient? {
        return (UIApplication.shared.delegate as! AppDelegate).client
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        self.client()?.call().delegate = self
    }

    @IBAction func actionCall(_ sender: UIButton) {
        if destination.text != "" && self.client()!.isStarted() {
            weak var call = client()!.call().callUserVideo(withId: destination.text)
            performSegue(withIdentifier: "callView", sender: call)
        }
    }

    func client(_ client: SINCallClient?, didReceiveIncomingCall call: SINCall?) {
        performSegue(withIdentifier: "callView", sender: call)
    }
}
  

致命错误:解开可选值时意外发现nil

0 个答案:

没有答案