Problem
Hello I am developing a swift application for IOS and using a MongoDB Realm database. I am having problems with Realm.asyncOpen(configuration: <#T##Realm.Configuration#>, callbackQueue: <#T##DispatchQueue#>, callback: <#T##(Result<Realm, Error>) -> Void#>) as it only works 90% of times (Around that percentage). I have tried the other variations of Realm.async() to see if it was just that function but it is not. I am using this function in my SplashScreen (First View Controller) in order to grab the realm and any changes done to it from my MongoDB Cluster as it using Realm Sync. Problem is that sometimes when it is called there is no callback being given, no result or fail, it’s just in an indefinite loop which lasts from a minute to ten minutes (normally takes couple seconds). This causes my animation screen to run indefinitely as I am waiting for the callback. Once this loop happens the next several runs are fine, but then it comes back again.
This is the printed console when the indefinite loop occurs:
User is logged in
2021-02-16 17:13:51.964779-0500 PlantersHandbook[2968:968859] Sync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
2021-02-16 17:13:52.051113-0500 PlantersHandbook[2968:968859] Sync: Connection[1]: Connected to endpoint ‘34.227.4.145:443’ (from ‘192.168.0.22:51480’)
Code
Note: Code does not get into the callback function when in the indefinite loop (1-10minutes)
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.navigationBar.isHidden = true
logoAnimationView.logoGifImageView.startAnimatingGif()
checkingConfiguration()
}
fileprivate func checkingConfiguration(){
if let _ = app.currentUser{
print("User is logged in")
var configuration = app.currentUser!.configuration(partitionValue: "user=\(app.currentUser!.id)", cancelAsyncOpenOnNonFatalErrors: true)
configuration.objectTypes = [User.self, Season.self, HandbookEntry.self, Block.self, SubBlock.self, Cache.self, BagUpInput.self, PlotInput.self, CoordinateInput.self, Coordinate.self, ExtraCash.self]
Realm.asyncOpen(configuration: configuration, callbackQueue: .main, callback: { result in
switch result {
case .failure( _):
print("Failed to load aysnc")
if Realm.fileExists(for: configuration){
self.enterapp(configuration: configuration, foundRealm: nil)
}else{
print("User not logged in; present sign in/sign up view")
self.navigationController?.pushViewController(WelcomeViewController(), animated: false)
}
case .success(let realm):
self.enterapp(configuration: configuration, foundRealm: realm)
}
})
}else {
print("User not logged in; present sign in/sign up view")
self.navigationController?.pushViewController(WelcomeViewController(), animated: false)
}
}
My Questions
Does anyone have similar problems? Can I set a timer somewhere to break the loop that is stuck and restart the Realm.asyncOpen somehow?
Set Up
Xcode 12.4
IOS Deployment Target - 14.3
Updated Cocoa Pods for Realm and RealmSwift