Browse files

Fix runtime error in iOS 4. Tweak activity polling.

* Was accidentally calling a UIProgressBar method that's not available till iOS 5.
* Throttle back activity poll interval to 2sec (from 0.5) while progress bar isn't active.
  • Loading branch information...
1 parent c9e0218 commit 525d7dc0b2296e7d2edab523a17f8f6d0d9ae574 @snej snej committed Aug 23, 2011
Showing with 14 additions and 9 deletions.
  1. +14 −9 Source/RootViewController.m
View
23 Source/RootViewController.m
@@ -286,16 +286,18 @@ - (void)updateSyncURL {
NSLog(@"Changing sync to <%@>", newRemoteURL.absoluteString);
self.remoteSyncURL = newRemoteURL;
[self stopSync];
- _pull = [[database pullFromDatabaseAtURL: newRemoteURL
- options: kCouchReplicationContinuous] retain];
- [_pull addObserver: self forKeyPath: @"status" options: 0 context: NULL];
-
- _push = [[database pushToDatabaseAtURL: newRemoteURL
- options: kCouchReplicationContinuous] retain];
- [_push addObserver: self forKeyPath: @"status" options: 0 context: NULL];
+ if (newRemoteURL) {
+ _pull = [[database pullFromDatabaseAtURL: newRemoteURL
+ options: kCouchReplicationContinuous] retain];
+ [_pull addObserver: self forKeyPath: @"status" options: 0 context: NULL];
+
+ _push = [[database pushToDatabaseAtURL: newRemoteURL
+ options: kCouchReplicationContinuous] retain];
+ [_push addObserver: self forKeyPath: @"status" options: 0 context: NULL];
+ database.server.activityPollInterval = 1.0;
+ }
}
- database.server.activityPollInterval = 0.5;
}
@@ -308,6 +310,7 @@ - (void) stopSync {
[_push stop];
[_push release];
_push = nil;
+ database.server.activityPollInterval = 0.0;
}
@@ -349,9 +352,11 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
NSLog(@"SYNC progress: %u / %u", completed, total);
if (total > 0 && completed < total) {
[self showSyncStatus];
- [progress setProgress:(completed / (float)total) animated:NO];
+ [progress setProgress:(completed / (float)total)];
+ database.server.activityPollInterval = 0.5; // poll often while progress is showing
} else {
[self showSyncButton];
+ database.server.activityPollInterval = 2.0; // poll less often at other times
}
}
}

0 comments on commit 525d7dc

Please sign in to comment.