Skip to content

[iOS] Applifecycle events such as applicationDidBecomeActive and applicationWillResignActive are not called on master version #170037

Open

Description

@hirosz

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 resources

Activity

  1. darshankawar commented on Jun 5, 2025

    @darshankawar
    Member

    @hirosz
    I tried this in latest stable version 3.32.1 and it prints all the states properly as below:

    🚀 application didFinishLaunchingWithOptions
    ✅ applicationDidBecomeActive - App is now active 
    🔧 Setting up method channel...
    🔗 Creating FlutterMethodChannel...
    ✅ Method channel created successfully
    ⚠️ applicationWillResignActive - App will become inactive
    ✅ applicationDidBecomeActive - App is now active
    📱 Method channel already exists
    ⚠️ applicationWillResignActive - App will become inactive 
    🌙 applicationDidEnterBackground - App is in background
    🌅 applicationWillEnterForeground - App will enter foreground
    ✅ applicationDidBecomeActive - App is now active
    📱 Method channel already exists
    

    I used iPhone 15 device. Are you saying these logs aren't printed for you ?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 5, 2025
  3. hirosz commented on Jun 5, 2025

    @hirosz
    Author

    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.

  4. hirosz commented on Jun 5, 2025

    @hirosz
    Author

    after delete UIApplicationSceneManifest from Info.plist it seems to work ok

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 5, 2025
  6. darshankawar commented on Jun 6, 2025

    @darshankawar
    Member

    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)

    🚀 application didFinishLaunchingWithOptions
    fopen failed for data file: errno = 2 (No such file or directory)
    Errors found! Invalidating cache...
    flutter: The Dart VM service is listening on http://0.0.0.0:59230/pSD7_UeCV7o=/
    fopen failed for data file: errno = 2 (No such file or directory)
    Errors found! Invalidating cache...
    FlutterView implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
    This FlutterEngine was already invoked.
    

    Master version: 3.33.0-1.0.pre.398

  7. added
    platform-iosiOS applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    c: regressionIt was better in the past than it is now
    team-iosOwned by iOS platform team
    and removed
    in triagePresently being triaged by the triage team
    on Jun 6, 2025
  8. changed the title [-][iOS] applicationDidBecomeActive not called[/-] [+][iOS] Applifecycle events such as `applicationDidBecomeActive` and `applicationWillResignActive` are not called on master version[/+] on Jun 6, 2025
  9. hellohuanlin commented on Jun 9, 2025

    @hellohuanlin
    Contributor

    If possible, you can subclass from FlutterSceneDelegate to get sceneWillResignActive called; If you have to use the AppDelegate, we likely have to relay the call from FlutterSceneDelegate to FlutterAppDelegate, similar to what's been done here: #170180

    I'm a bit iffy about relaying the call: Apple's behavior is that if you adopt SceneDelegate, the AppDelegate's applicationWillResignActive will 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)

  10. added
    P1High-priority issues at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Jun 12, 2025
  11. flutter-triage-bot commented on Oct 16, 2025

    @flutter-triage-bot

    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!

  12. added
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    and removed
    P1High-priority issues at the top of the work list
    on Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowfound in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions