'Problem with Firebase Firestore when calling on App Delegate swift
I want to make a firestore call every time the app launches. but the line of accessing firestore or the completion is not being executed.
class MoodAnalysisFirestoreManager{
private let db = Firestore.firestore()
static let shared = MoodAnalysisFirestoreManager()
private let currentUser = AuthManager.shared().getCurrentUserSafe()!
private init(){}
public func addNewDayToCloud(){
let todayName = Date().getTodayName(date: Date()).uppercased()
let safeDate = safeDateString(date: Date())
let ref = db.collection("MoodAnalysis").document(currentUser)
ref.collection("analysis").document(safeDate).setData([
"day": todayName,
"date": Date(),
"neutralCount": 0,
"angryCount": 0,
"sadCount": 0,
"happyCount": 0,
"Count":0,
"emotionVal":0
]){
error in
print(error)
}
}
app delegate function
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
let db = Firestore.firestore()
print(db)
MoodAnalysisFirestoreManager.shared.addNewDayToCloud()
return true
}
if I called MoodAnalysisFirestoreManager.shared.addNewDayToCloud() from the app delegate it does not add anything to the firestore, but if I make any type of retrieving data from the cloud it works fine or, calls this function in other view controllers everything works fine.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
