当我尝试将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