Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temporary disconnect when app goes inactive #13564

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading