Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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 应用程序终止时,用户未注销_Ios_Swift_Xcode - Fatal编程技术网

Ios 应用程序终止时,用户未注销

Ios 应用程序终止时,用户未注销,ios,swift,xcode,Ios,Swift,Xcode,我正在做一个聊天应用程序,但是当用户终止该应用程序时,一个好的做法是注销该用户并将其删除。然而,当用户终止应用程序时,如果我打印一些东西,它将被打印,但是当我把代码放在用户注销时,代码似乎没有被执行,我不知道为什么 这是代码: func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { Auth

我正在做一个聊天应用程序,但是当用户终止该应用程序时,一个好的做法是注销该用户并将其删除。然而,当用户终止应用程序时,如果我打印一些东西,它将被打印,但是当我把代码放在用户注销时,代码似乎没有被执行,我不知道为什么

这是代码:

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        
        Auth.auth().currentUser?.delete(completion: { (error) in
            
            if error == nil {
                
                do{
                    try Auth.auth().signOut()
                    print("user has been logged out without problems!")
                    
                }catch{
                    print("there was an error when trying executing logout function")
                }
            }
        })
    }
    
    func applicationWillTerminate(_ application: UIApplication) {
        Auth.auth().currentUser?.delete(completion: { (error) in
            
            if error == nil {
                
                do{
                    try Auth.auth().signOut()
                    print("user has been logged out without problems!")
                    
                }catch{
                    print("there was an error when trying executing logout function")
                }
            }
        })
    }
func应用程序(application:UIApplication,didDiscardSceneSessions sceneSessions:Set){
Auth.Auth().currentUser?.delete(完成:{(错误)在中)
如果错误==nil{
做{
请尝试Auth.Auth().signOut()
打印(“用户已顺利注销!”)
}抓住{
打印(“尝试执行注销功能时出错”)
}
}
})
}
func应用程序将终止(application:UIApplication){
Auth.Auth().currentUser?.delete(完成:{(错误)在中)
如果错误==nil{
做{
请尝试Auth.Auth().signOut()
打印(“用户已顺利注销!”)
}抓住{
打印(“尝试执行注销功能时出错”)
}
}
})
}

当用户终止应用程序时,有没有执行此代码的解决方案?

我试图刺激您的代码,但我注意到了这个问题

从我可以看出(也许):

  • 应用程序没有提供完成代码的时间
  • 您正在删除该用户,然后将其注销
    Auth.Auth().currentUser?.delete
  • 我尝试了此代码,它似乎工作正常,没有问题:

        do{
            Auth.auth().currentUser?.delete(completion: nil)
            try Auth.auth().signOut()
            print("user has been logged out without problems!")
            
        }catch{
            print("there was an error when trying executing logout function")
        }
    

    Auth.Auth()如何让用户登录和注销?@GarethPrice当用户输入他的电子邮件时,将生成一个随机密码,他将登录,这个功能在使用button时没有问题,但是当应用程序终止时它就不工作了。我不明白为什么你没有足够的执行时间来执行网络操作。无论如何,您不能依赖于总是调用该方法。为什么不让用户在执行期间登录?或者只是让他们重新验证launch@Paulw11我的应用程序是基于速度的,所以用户不需要执行所有这些步骤,只需直接使用用户名、年龄和登录即可。您不需要注册或其他什么,在这种情况下,我将是法官,以确保用户注销时,应用程序终止和离线时,应用程序是在后台不幸的是,我不认为这是你将能够实现的东西,仅在应用程序方面。您可能需要您的应用程序向服务器发送“保持活动”消息,并让服务器在错过一些保持活动后将用户显示为脱机。用户可以终止应用程序,而无需调用
    willTerminate