mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Keep resident runner connected on iOS when screen locks in debug mode (flutter/engine#3610)
* Add debug mode background * Review notes
This commit is contained in:
parent
0e9ba7f5e7
commit
7900afc2fa
@ -15,6 +15,8 @@
|
||||
* This class provides the following behaviors:
|
||||
* * Status bar touches are forwarded to the key window's root view
|
||||
* FlutterViewController, in order to trigger scroll to top.
|
||||
* * Keeps the Flutter connection open in debug mode when the phone screen
|
||||
* locks.
|
||||
*
|
||||
* App delegates for Flutter applications are *not* required to inherit from
|
||||
* this class. Developers of custom app delegate classes should copy and paste
|
||||
|
||||
@ -4,8 +4,11 @@
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||
#include "lib/ftl/logging.h"
|
||||
|
||||
@implementation FlutterAppDelegate
|
||||
@implementation FlutterAppDelegate {
|
||||
UIBackgroundTaskIdentifier _debugBackgroundTask;
|
||||
}
|
||||
|
||||
// Returns the key window's rootViewController, if it's a FlutterViewController.
|
||||
// Otherwise, returns nil.
|
||||
@ -26,4 +29,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
// The following keeps the Flutter session alive when the device screen locks
|
||||
// in debug mode. It allows continued use of features like hot reload and
|
||||
// taking screenshots once the device unlocks again.
|
||||
//
|
||||
// Note the name is not an identifier and multiple instances can exist.
|
||||
_debugBackgroundTask = [application beginBackgroundTaskWithName:@"Flutter debug task"
|
||||
expirationHandler:^{
|
||||
FTL_LOG(WARNING) << "\nThe OS has terminated the Flutter debug connection for being "
|
||||
"inactive in the background for too long.\n\n"
|
||||
"There are no errors with your Flutter application.\n\n"
|
||||
"To reconnect, launch your application again via 'flutter run";
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
[application endBackgroundTask: _debugBackgroundTask];
|
||||
}
|
||||
#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user