From 20f216baa7a723471fa1663c07f679e91e8e2ce0 Mon Sep 17 00:00:00 2001 From: Dang Dat Date: Thu, 7 May 2026 15:54:54 +0700 Subject: [PATCH] HOTFIX Support iOS 26 --- ios/Runner.xcodeproj/project.pbxproj | 4 +++ ios/Runner/AppDelegate.swift | 43 +++++++--------------------- ios/Runner/Info.plist | 21 ++++++++++++++ ios/Runner/SceneDelegate.swift | 28 ++++++++++++++++++ pubspec.lock | 6 ++-- pubspec.yaml | 3 +- 6 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 ios/Runner/SceneDelegate.swift diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 3b1202f90..923afe52a 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; B561AD69C2BE6DF40BF29406 /* Pods_TwakeMailNSE.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA243B93F65E4E3CD7DC0348 /* Pods_TwakeMailNSE.framework */; }; + C06B95712FAC780E009C15B4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C06B95702FAC7800009C15B4 /* SceneDelegate.swift */; }; CDFECA8C54311B749F044831 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5810EDDA99BEFEACD742F507 /* Pods_Runner.framework */; }; F522E87F2C0EE23400DDA35B /* AuthenticationSSOTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F522E87E2C0EE23400DDA35B /* AuthenticationSSOTests.swift */; }; F522E8812C0EE3F200DDA35B /* AuthenticationSSO.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E7D8832B3877050009BB8A /* AuthenticationSSO.swift */; }; @@ -147,6 +148,7 @@ AF31502A83CA492E27C36A7B /* Pods-TwakeMailNSE.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TwakeMailNSE.profile.xcconfig"; path = "Target Support Files/Pods-TwakeMailNSE/Pods-TwakeMailNSE.profile.xcconfig"; sourceTree = ""; }; B2EAFF659572E6B9F5AFAAF8 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; BC08294F5AE09BF8CC592AD1 /* Pods-TeamMailShareExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TeamMailShareExtension.release.xcconfig"; path = "Target Support Files/Pods-TeamMailShareExtension/Pods-TeamMailShareExtension.release.xcconfig"; sourceTree = ""; }; + C06B95702FAC7800009C15B4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; EA243B93F65E4E3CD7DC0348 /* Pods_TwakeMailNSE.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TwakeMailNSE.framework; sourceTree = BUILT_PRODUCTS_DIR; }; F522E87E2C0EE23400DDA35B /* AuthenticationSSOTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationSSOTests.swift; sourceTree = ""; }; F522E8852C0EE8B600DDA35B /* CoreUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreUtils.swift; sourceTree = ""; }; @@ -284,6 +286,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + C06B95702FAC7800009C15B4 /* SceneDelegate.swift */, 4D124E74293A67D900BA5186 /* RunnerProfile.entitlements */, F52F993D27FD733C00346091 /* Runner.entitlements */, 97C146FA1CF9000F007C117D /* Main.storyboard */, @@ -836,6 +839,7 @@ F522E8862C0EE8B600DDA35B /* CoreUtils.swift in Sources */, F522E8812C0EE3F200DDA35B /* AuthenticationSSO.swift in Sources */, F522E8822C0EE48700DDA35B /* AuthenticationType.swift in Sources */, + C06B95712FAC780E009C15B4 /* SceneDelegate.swift in Sources */, F5EFC07D2B328B9F00829056 /* TwakeLogger.swift in Sources */, F5E7D8742B3578F90009BB8A /* JmapConstants.swift in Sources */, F522E8832C0EE48C00DDA35B /* Authentication.swift in Sources */, diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 27500c86d..cfda67f3a 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -4,7 +4,7 @@ import receive_sharing_intent import flutter_local_notifications @main -@objc class AppDelegate: FlutterAppDelegate { +@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate { var notificationInteractionChannel: FlutterMethodChannel? var fcmMethodChannel: FlutterMethodChannel? @@ -14,11 +14,6 @@ import flutter_local_notifications _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - GeneratedPluginRegistrant.register(with: self) - - createNotificationInteractionChannel() - createFcmMethodChannel() - if let payload = launchOptions?[.remoteNotification] as? [AnyHashable : Any], let emailId = payload[JmapConstants.EMAIL_ID] as? String, !emailId.isEmpty { @@ -46,9 +41,12 @@ import flutter_local_notifications return super.application(application, didFinishLaunchingWithOptions: launchOptions) } - - override func applicationDidEnterBackground(_ application: UIApplication) { - updateApplicationStateInUserDefaults(false) + + func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) { + GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry) + + createNotificationInteractionChannel(engineBridge.applicationRegistrar.messenger()) + createFcmMethodChannel(engineBridge.applicationRegistrar.messenger()) } override func applicationWillTerminate(_ application: UIApplication) { @@ -70,11 +68,6 @@ import flutter_local_notifications return super.application(app, open: url, options:options) } - override func applicationDidBecomeActive(_ application: UIApplication) { - removeAppBadger() - updateApplicationStateInUserDefaults(true) - } - private func handleEmailAndress(open url: URL) -> URL? { let appDomain = Bundle.main.bundleIdentifier! let appGroupId = (Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String) ?? "group.\(Bundle.main.bundleIdentifier!)" @@ -150,22 +143,10 @@ extension AppDelegate { } } - private func removeAppBadger() { - TwakeLogger.shared.log(message: "AppDelegate::removeAppBadger") - if #available(iOS 16.0, *) { - UNUserNotificationCenter.current().setBadgeCount(0) - } else { - UIApplication.shared.applicationIconBadgeNumber = 0 - - } - } - - private func createNotificationInteractionChannel() { - let controller : FlutterViewController = window?.rootViewController as! FlutterViewController - + private func createNotificationInteractionChannel(_ binaryMessenger: FlutterBinaryMessenger) { self.notificationInteractionChannel = FlutterMethodChannel( name: CoreUtils.NOTIFICATION_INTERACTION_CHANNEL_NAME, - binaryMessenger: controller.binaryMessenger + binaryMessenger: binaryMessenger ) self.notificationInteractionChannel?.setMethodCallHandler { (call, result) in @@ -179,12 +160,10 @@ extension AppDelegate { } } - private func createFcmMethodChannel() { - let controller : FlutterViewController = window?.rootViewController as! FlutterViewController - + private func createFcmMethodChannel(_ binaryMessenger: FlutterBinaryMessenger) { self.fcmMethodChannel = FlutterMethodChannel( name: CoreUtils.FCM_METHOD_CHANNEL_NAME, - binaryMessenger: controller.binaryMessenger + binaryMessenger: binaryMessenger ) } diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 0264ea0f9..c13fdd9a5 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -94,5 +94,26 @@ UIStatusBarHidden + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneClassName + UIWindowScene + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneConfigurationName + flutter + UISceneStoryboardFile + Main + + + + diff --git a/ios/Runner/SceneDelegate.swift b/ios/Runner/SceneDelegate.swift new file mode 100644 index 000000000..d94c71153 --- /dev/null +++ b/ios/Runner/SceneDelegate.swift @@ -0,0 +1,28 @@ +import Flutter +import UIKit + +class SceneDelegate: FlutterSceneDelegate { + override func sceneDidBecomeActive(_ scene: UIScene) { + removeAppBadger() + updateApplicationStateInUserDefaults(true) + } + + override func sceneDidEnterBackground(_ scene: UIScene) { + updateApplicationStateInUserDefaults(false) + } + + private func removeAppBadger() { + TwakeLogger.shared.log(message: "AppDelegate::removeAppBadger") + if #available(iOS 16.0, *) { + UNUserNotificationCenter.current().setBadgeCount(0) + } else { + UIApplication.shared.applicationIconBadgeNumber = 0 + } + } + + private func updateApplicationStateInUserDefaults(_ appIsActive: Bool) { + let appGroupId = (Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String) ?? "group.\(Bundle.main.bundleIdentifier!)" + let userDefaults = UserDefaults(suiteName: appGroupId) + userDefaults?.set(appIsActive, forKey: CoreUtils.APPLICATION_STATE) + } +} diff --git a/pubspec.lock b/pubspec.lock index 643c65d7e..8a6f12d8f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -292,11 +292,11 @@ packages: dependency: "direct main" description: path: "." - ref: master - resolved-ref: d39739e8e9a43bba2c6ea6c885653c615e114e07 + ref: "hotfix/migrate-ios-26" + resolved-ref: "61ceb0751a564f8d687cb51bb4d6298737e2b9dc" url: "https://github.com/linagora/flutter_contacts.git" source: git - version: "0.6.3" + version: "0.6.4" convert: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 64aa7c409..fd32f5283 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -76,10 +76,11 @@ dependencies: url: https://github.com/linagora/jmap-dart-client.git ref: main + # TODO: Revert when https://github.com/linagora/flutter_contacts/pull/13 is merged contacts_service: git: url: https://github.com/linagora/flutter_contacts.git - ref: master + ref: hotfix/migrate-ios-26 receive_sharing_intent: git: