diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a34ef2f61..c5ab2b3c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ x.y.z Release notes (yyyy-MM-dd) ============================================================= ### Enhancements -* None. +* Expose `SyncSession.reconnect()`, which requests an immediate reconnection if + the session is currently disconnected rather than waiting for the normal + reconnect delay. ### Fixed * ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?) diff --git a/Realm/RLMSyncSession.h b/Realm/RLMSyncSession.h index 31677ce9c4..2cf1c9359e 100644 --- a/Realm/RLMSyncSession.h +++ b/Realm/RLMSyncSession.h @@ -160,6 +160,23 @@ RLM_SWIFT_SENDABLE RLM_FINAL // is internally thread-safe */ - (void)resume; +/** + Request an immediate reconnection to the server if the session is disconnected. + + Realm automatically reconnects after disconnects with an exponential backoff, + which is reset when the reachability handler reports a network status change. + In some scenarios an application may wish to skip the reconnect delay, such as + when an application receives the DidBecomeActive notification, which can be + done by calling this method. Calling this method is never required. + + This method is asynchronous and merely skips the current reconnect delay, so + the connection state will still normally be disconnected immediately after + calling it. + + Has no effect if the session is currently connected. + */ +- (void)reconnect; + /** Register a progress notification block. diff --git a/Realm/RLMSyncSession.mm b/Realm/RLMSyncSession.mm index f181db3855..98d562acc0 100644 --- a/Realm/RLMSyncSession.mm +++ b/Realm/RLMSyncSession.mm @@ -174,6 +174,12 @@ - (void)unpause { } } +- (void)reconnect { + if (auto session = _session.lock()) { + session->handle_reconnect(); + } +} + static util::UniqueFunction wrapCompletion(dispatch_queue_t queue, void (^callback)(NSError *)) { queue = queue ?: dispatch_get_main_queue();