I’m having trouble pinning down when replication is complete on app launch. In other words, when replication the first time is done.
I have a loading splash screen where I need everything replicated before letting the user in. Calculating the percentage is easy enough and in the docs, but there are many different exceptions in the replication which makes this not straight forward.
This is how my code looks like for kCBLReplicationChangeNotification
:
if pull.status == .Active || push.status == .Active {
let total = Float(push.changesCount + pull.changesCount)
if total > 0 {
let completed = Float(push.completedChangesCount + pull.completedChangesCount)
let percent = completed / total
progressView.progress = percent
if !replicationComplete && percent >= 0.99 {
replicationComplete = true
startSession()
}
}
}
A few things I’m hoping someone can help shed light on:
-
Replication percentage always ends up as something like
0.999783
, but never1
. Is this expected? -
What if there’s nothing to replicate for the user, the total will be
zero
and the user’s splash screen will never finish or reach100%
? -
What if there’s no internet, does it timeout back to
idle
state?
I’m sort of confused and wish there was a replication.complete
flag, because [active, idle, offline, stopped]
isn’t what it seems, such as offline
isn’t the same as no internet, and idle
kind of means complete but not really. Also if the total
isn’t determined yet, -1
would be more clear I think since zero
just gives total
another meaning in some cases.
Any help or advise would be greatly appreciated to accomplish a splash screen that fully completes replication before letting the user into the app.