Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): leaving the iOS app for a few seconds no longer drops the connection #26540

Mergedanaclumos(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/26540/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 25 additions and 1 deletion.

x
0 of 2 viewed, 2 left
23 additions and 0 deletionsapps/mobile/modules/t3-native-controls/ios/T3BackgroundGraceSubscriber.swiftAdded
View file
@@ -0,0 +1,23 @@
+import ExpoModulesCore
+import UIKit
+​
+public final class T3BackgroundGraceSubscriber: ExpoAppDelegateSubscriber {
+ private var task = UIBackgroundTaskIdentifier.invalid
+​
+ public func applicationWillResignActive(_ application: UIApplication) {
+ guard task == .invalid else { return }
+ task = application.beginBackgroundTask(withName: "T3 connection grace") { [weak self] in
+ self?.endTask(application)
+ }
+ }
+​
+ public func applicationDidBecomeActive(_ application: UIApplication) {
+ endTask(application)
+ }
+​
+ private func endTask(_ application: UIApplication) {
+ guard task != .invalid else { return }
+ application.endBackgroundTask(task)
+ task = .invalid
+ }
+}
2 additions and 1 deletionapps/mobile/modules/t3-native-controls/expo-module.config.jsonModified
View file
@@ -4,7 +4,8 @@
"modules": ["T3NativeControlsModule", "T3KeyboardCommandsModule"],
"appDelegateSubscribers": [
"T3WorkspaceOrientationSubscriber",