Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.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
Ios 应用程序转到后台时的Socket.io连接_Ios_Swift - Fatal编程技术网

Ios 应用程序转到后台时的Socket.io连接

Ios 应用程序转到后台时的Socket.io连接,ios,swift,Ios,Swift,我正在swift中使用socket.io客户端 图书馆: 你知道,在ios中,当一个应用程序进入后台时,可能所有东西都会切换到暂停模式。当我的应用程序进入后台,然后在2分钟后进入前台时,此库不会立即连接到服务器。我想当应用程序转到后台时,我必须关闭套接字连接,然后当转到前台时,我必须重新连接 为此,我使用以下方法: func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that

我正在swift中使用socket.io客户端

图书馆:

你知道,在ios中,当一个应用程序进入后台时,可能所有东西都会切换到暂停模式。当我的应用程序进入后台,然后在2分钟后进入前台时,此库不会立即连接到服务器。我想当应用程序转到后台时,我必须关闭套接字连接,然后当转到前台时,我必须重新连接

为此,我使用以下方法:

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    socket.reconnect()

}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    socket.close()
}
但不起作用。当应用程序来到前台时,我完全断开了和服务器的连接

我知道这是一个很难解决的问题。但我猜有人在Stackoverflow使用这个库


我如何处理这种情况?

嘿,你为什么不尝试在applicationWillEnterForeground(应用程序:UIApplication)中重新连接,看看这是否有效。@托尔盖:我也面临同样的问题,你找到解决方法了吗。如果是的话,请分享给我。同样在这里与普瑟斯维夫特。