Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift:每个load viewcontroller函数运行几次_Swift_Quickblox - Fatal编程技术网

Swift:每个load viewcontroller函数运行几次

Swift:每个load viewcontroller函数运行几次,swift,quickblox,Swift,Quickblox,我在viewController.swift中使用以下代码 func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) { print("PLAY SESSION") } 我打开应用程序,在接收会话后,我得到一个日志播放会话 但如果我打开应用程序,进入viewControllerPage.swift,然后再次返回viewController.swift,在接收会话之后,我会

我在
viewController.swift中使用以下代码

func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
    print("PLAY SESSION")
}
我打开应用程序,在接收会话后,我得到一个日志
播放会话

但如果我打开应用程序,进入
viewControllerPage.swift
,然后再次返回
viewController.swift
,在接收会话之后,我会得到两个日志
播放会话

因此,如果我打开
viewController.swift
7-8次,在接收会话后打印7-8次
PLAY会话

我只想获得一次会话,即使每次打开
viewController.swift

func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
    print("PLAY SESSION")
}

我想要
direceivenewsession
加载一次这正是viewDidload和ViewDidDisplay的用途

override func viewDidLoad() {
    //insert the code you only want to run once here
}

override func viewDidAppear(_ animated: Bool){
    //insert the code you want to run every time you load the VC
}

你不想使用它们有什么特别的原因吗?或者,您可以使用ViewWillAspect()而不是ViewDidAspect()

这正是viewDidload和ViewDidAspect的用途

override func viewDidLoad() {
    //insert the code you only want to run once here
}

override func viewDidAppear(_ animated: Bool){
    //insert the code you want to run every time you load the VC
}
你不想使用它们有什么特别的原因吗?或者,您可以使用ViewWillAspect()而不是ViewDidAspect()