So I am building a chat app, one thing in most chat apps is a status. I want to be able to see who is online and using my app. I have all the functions set up and everything. these two functions that I have that are supposed to be called when the app enters foreground and background don't seem to be called. at all.
func applicationDidEnterBackground(_ application: UIApplication) {
guard let userId = UserDefaults.standard.string(forKey: "uuid") else { return }
print(userId)
FirebaseManager().updateUserStatusOnDisconnect(status: false, userId: userId)
print("No longer using the app")
}
func applicationWillEnterForeground(_ application: UIApplication) {
guard let userId = UserDefaults.standard.string(forKey: "uuid") else { return }
print(userId)
FirebaseManager().updateUserStatusOnDisconnect(status: true, userId: userId)
print("Using the app")
}
I don't even know if I have written these correctly or not, but I need the functions to be called for me to even understand what is going on.
What should be happening?
When the app enters into the background it's going to call the updateUserStatusOnDisconnect function that is in my FirebaseManager file. this function will update the status to the database to appear offline and all of the flashy viewings will be toggled.
For when the app enters the foreground it will do the same thing except update the the database with users status to be true, as he or she will be online.
Any help that can be brought to light for me will be greatly appreciated. I am fairly new to SwiftUI and just apple development in general. Ive only started 6 days ago, and im going strong. Just stuck on some problems that google can't even help with.