Skip to content

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

Open
@hirosz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues 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