Skip to content

Commit

Permalink
Fix temporary disconnect when app goes inactive (#13564)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Sep 3, 2024
1 parent d1b950f commit 936ddf4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 49 deletions.
4 changes: 4 additions & 0 deletions FirebaseDatabase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased
- [fixed] Fix temporary disconnects when the app goes inactive. The issue was
introduced in 10.27.0. (#13529)

# 11.0.0
- [removed] **Breaking change**: The deprecated `FirebaseDatabaseSwift`
module has been removed. See
Expand Down
30 changes: 2 additions & 28 deletions FirebaseDatabase/Sources/Core/FPersistentConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
#import "FirebaseDatabase/Sources/Utilities/FUtilities.h"
#import "FirebaseDatabase/Sources/Utilities/Tuples/FTupleCallbackStatus.h"
#import "FirebaseDatabase/Sources/Utilities/Tuples/FTupleOnDisconnect.h"
#if TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
#else
#if !TARGET_OS_WATCH
#import <SystemConfiguration/SystemConfiguration.h>
#endif // TARGET_OS_WATCH
#endif // !TARGET_OS_WATCH
#import <dlfcn.h>
#import <netinet/in.h>

Expand Down Expand Up @@ -168,7 +166,6 @@ - (id)initWithRepoInfo:(FRepoInfo *)repoInfo
retryExponent:kPersistentConnReconnectMultiplier
jitterFactor:0.7];

[self setupNotifications];
// Make sure we don't actually connect until open is called
[self interruptForReason:kFInterruptReasonWaitingForOpen];
}
Expand Down Expand Up @@ -553,29 +550,6 @@ - (void)openNetworkConnectionWithContext:
[self.realtime open];
}

- (void)enteringForeground {
dispatch_async(self.dispatchQueue, ^{
// Reset reconnect delay
[self.retryHelper signalSuccess];
if (self->connectionState == ConnectionStateDisconnected) {
[self tryScheduleReconnect];
}
});
}

- (void)setupNotifications {
#if TARGET_OS_WATCH
__weak FPersistentConnection *weakSelf = self;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserverForName:WKApplicationWillEnterForegroundNotification
object:nil
queue:nil
usingBlock:^(NSNotification *_Nonnull note) {
[weakSelf enteringForeground];
}];
#endif // TARGET_OS_WATCH
}

- (void)sendAuthAndRestoreStateAfterComplete:(BOOL)restoreStateAfterComplete {
NSAssert([self connected], @"Must be connected to send auth");
NSAssert(self.authToken != nil,
Expand Down
21 changes: 0 additions & 21 deletions FirebaseDatabase/Sources/Realtime/FWebSocketConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,6 @@ - (instancetype)initWith:(FRepoInfo *)repoInfo
NSURLSessionWebSocketTask *task =
[session webSocketTaskWithRequest:req];
self.webSocketTask = task;

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION || TARGET_OS_MACCATALYST
NSString *resignName = UIApplicationWillResignActiveNotification;
#elif TARGET_OS_OSX
NSString *resignName = NSApplicationWillResignActiveNotification;
#elif TARGET_OS_WATCH
NSString *resignName = WKApplicationWillResignActiveNotification;
#elif
#error("missing platform")
#endif
[[NSNotificationCenter defaultCenter]
addObserverForName:resignName
object:nil
queue:opQueue
usingBlock:^(NSNotification *_Nonnull note) {
FFLog(@"I-RDB083015",
@"Received notification that application "
@"will resign, "
@"closing web socket.");
[self onClosed];
}];
}
}
return self;
Expand Down

0 comments on commit 936ddf4

Please sign in to comment.