Repository navigation
[iOS] Applifecycle events such as applicationDidBecomeActive and applicationWillResignActive are not called on master version #170037
Copy link
Copy link
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.33Found to occur in 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyteam-iosOwned by iOS platform teamOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamTriaged by iOS platform teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Description
Steps to reproduce
applicationDidBecomeActive, applicationWillResignActive etc don't call. It works with other iOS projects but not with Flutter
Expected results
call applicationDidBecomeActive, applicationWillResignActive etc
Actual results
nothing happen
Code sample
Code sample
import Flutter
import UIKit
import AVFoundation
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
var batteryChannel: FlutterMethodChannel?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print("🚀 application didFinishLaunchingWithOptions")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func applicationDidBecomeActive(_ application: UIApplication) {
super.applicationDidBecomeActive(application)
print("✅ applicationDidBecomeActive - App is now active")
if batteryChannel == nil {
print("🔧 Setting up method channel...")
setupMethodChannel()
} else {
print("📱 Method channel already exists")
}
}
override func applicationWillResignActive(_ application: UIApplication) {
super.applicationWillResignActive(application)
print("⚠️ applicationWillResignActive - App will become inactive")
}
override func applicationDidEnterBackground(_ application: UIApplication) {
super.applicationDidEnterBackground(application)
print("🌙 applicationDidEnterBackground - App is in background")
}
override func applicationWillEnterForeground(_ application: UIApplication) {
super.applicationWillEnterForeground(application)
print("🌅 applicationWillEnterForeground - App will enter foreground")
}
override func applicationWillTerminate(_ application: UIApplication) {
super.applicationWillTerminate(application)
print("💀 applicationWillTerminate - App will terminate")
}
private func setupMethodChannel() {
guard let controller = window?.rootViewController as? FlutterViewController else {
print("❌ FlutterViewController not available")
return
}
print("🔗 Creating FlutterMethodChannel...")
batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
binaryMessenger: controller.binaryMessenger)
print("✅ Method channel created successfully")
}
}Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel main, 3.33.0-1.0.pre.380, on macOS 15.5 24F74 darwin-arm64, locale pl-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.100.2)
[✓] Connected device (3 available)
[✓] Network resourcesReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.33Found to occur in 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyteam-iosOwned by iOS platform teamOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamTriaged by iOS platform teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Activity
darshankawar commentedon Jun 5, 2025
@hirosz
I tried this in latest stable version 3.32.1 and it prints all the states properly as below:
I used iPhone 15 device. Are you saying these logs aren't printed for you ?
hirosz commentedon Jun 5, 2025
I tested on an older flutter version and it seems that everything works properly before 3.33.x. So the issue is for flutter >33.3.x.
hirosz commentedon Jun 5, 2025
after delete UIApplicationSceneManifest from Info.plist it seems to work ok
darshankawar commentedon Jun 6, 2025
Thanks for the update. I tried on latest master and in it, it seems to not trigger the said events, as I see below as compared to what I observed in latest stable : #170037 (comment)
Master version: 3.33.0-1.0.pre.398[-][iOS] applicationDidBecomeActive not called[/-][+][iOS] Applifecycle events such as `applicationDidBecomeActive` and `applicationWillResignActive` are not called on master version[/+]hellohuanlin commentedon Jun 9, 2025
If possible, you can subclass from
FlutterSceneDelegateto getsceneWillResignActivecalled; If you have to use theAppDelegate, we likely have to relay the call fromFlutterSceneDelegatetoFlutterAppDelegate, similar to what's been done here: #170180I'm a bit iffy about relaying the call: Apple's behavior is that if you adopt SceneDelegate, the AppDelegate's
applicationWillResignActivewill not be called anymore. This totally makes sense, because "active" vs "inactive" is scene concept rather than app concept now - one app can have both active and inactive scenes.Relaying the calls changes this behavior. It's very unlikely that people implement both versions, so I am not too worried about it for now. However, I feel this kind of change may bite us down the road. At least it's worth a discussion (and documentation if we go with relaying the calls)
flutter-triage-bot commentedon Oct 16, 2025
This issue is marked P1 but has had no recent status updates.
The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.
Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!