iOS: Migrate FlutterAppDelegate to ARC (#55472)
Migrates the FlutterAppDelegate.mm translation unit to be compiled with the `-fobjc-arc` compiler flag.
No test changes since no this change includes no semantic changes, and thus covered by existing tests such as [`testReleasesWindowOnDealloc`](https://github.com/flutter/engine/blob/3dfb4622de88abb48ce65be56ff29422ab43805f/shell/platform/darwin/ios/framework/Source/FlutterAppDelegateTest.mm#L139-L153).
Issue: https://github.com/flutter/flutter/issues/137801
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn
index 7b821c2..62b8f60 100644
--- a/shell/platform/darwin/ios/BUILD.gn
+++ b/shell/platform/darwin/ios/BUILD.gn
@@ -59,6 +59,7 @@
public_configs = [ "//flutter:config" ]
sources = [
+ "framework/Source/FlutterAppDelegate.mm",
"framework/Source/FlutterCallbackCache.mm",
"framework/Source/FlutterCallbackCache_Internal.h",
"framework/Source/FlutterChannelKeyResponder.h",
@@ -179,7 +180,6 @@
# iOS embedder is migrating to ARC.
# New files are highly encouraged to be in ARC.
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
- "framework/Source/FlutterAppDelegate.mm",
"framework/Source/FlutterEngine.mm",
"framework/Source/FlutterEngineGroup.mm",
"framework/Source/FlutterEngine_Internal.h",
diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm
index 6f784e7..1831cd3 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm
+++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm
@@ -11,6 +11,8 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate_internal.h"
+FLUTTER_ASSERT_ARC
+
static NSString* const kUIBackgroundMode = @"UIBackgroundModes";
static NSString* const kRemoteNotificationCapabitiliy = @"remote-notification";
static NSString* const kBackgroundFetchCapatibility = @"fetch";
@@ -18,11 +20,10 @@
@interface FlutterAppDelegate ()
@property(nonatomic, copy) FlutterViewController* (^rootFlutterViewControllerGetter)(void);
+@property(nonatomic, strong) FlutterPluginAppLifeCycleDelegate* lifeCycleDelegate;
@end
-@implementation FlutterAppDelegate {
- FlutterPluginAppLifeCycleDelegate* _lifeCycleDelegate;
-}
+@implementation FlutterAppDelegate
- (instancetype)init {
if (self = [super init]) {
@@ -31,21 +32,16 @@
return self;
}
-- (void)dealloc {
- [_lifeCycleDelegate release];
- [_rootFlutterViewControllerGetter release];
- [_window release];
- [super dealloc];
-}
-
- (BOOL)application:(UIApplication*)application
willFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
- return [_lifeCycleDelegate application:application willFinishLaunchingWithOptions:launchOptions];
+ return [self.lifeCycleDelegate application:application
+ willFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
- return [_lifeCycleDelegate application:application didFinishLaunchingWithOptions:launchOptions];
+ return [self.lifeCycleDelegate application:application
+ didFinishLaunchingWithOptions:launchOptions];
}
// Returns the key window's rootViewController, if it's a FlutterViewController.
@@ -85,20 +81,20 @@
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (void)application:(UIApplication*)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings {
- [_lifeCycleDelegate application:application
+ [self.lifeCycleDelegate application:application
didRegisterUserNotificationSettings:notificationSettings];
}
#pragma GCC diagnostic pop
- (void)application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
- [_lifeCycleDelegate application:application
+ [self.lifeCycleDelegate application:application
didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
- [_lifeCycleDelegate application:application
+ [self.lifeCycleDelegate application:application
didFailToRegisterForRemoteNotificationsWithError:error];
}
@@ -106,7 +102,7 @@
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (void)application:(UIApplication*)application
didReceiveLocalNotification:(UILocalNotification*)notification {
- [_lifeCycleDelegate application:application didReceiveLocalNotification:notification];
+ [self.lifeCycleDelegate application:application didReceiveLocalNotification:notification];
}
#pragma GCC diagnostic pop
@@ -114,10 +110,10 @@
willPresentNotification:(UNNotification*)notification
withCompletionHandler:
(void (^)(UNNotificationPresentationOptions options))completionHandler {
- if ([_lifeCycleDelegate respondsToSelector:_cmd]) {
- [_lifeCycleDelegate userNotificationCenter:center
- willPresentNotification:notification
- withCompletionHandler:completionHandler];
+ if ([self.lifeCycleDelegate respondsToSelector:_cmd]) {
+ [self.lifeCycleDelegate userNotificationCenter:center
+ willPresentNotification:notification
+ withCompletionHandler:completionHandler];
}
}
@@ -127,10 +123,10 @@
- (void)userNotificationCenter:(UNUserNotificationCenter*)center
didReceiveNotificationResponse:(UNNotificationResponse*)response
withCompletionHandler:(void (^)(void))completionHandler {
- if ([_lifeCycleDelegate respondsToSelector:_cmd]) {
- [_lifeCycleDelegate userNotificationCenter:center
- didReceiveNotificationResponse:response
- withCompletionHandler:completionHandler];
+ if ([self.lifeCycleDelegate respondsToSelector:_cmd]) {
+ [self.lifeCycleDelegate userNotificationCenter:center
+ didReceiveNotificationResponse:response
+ withCompletionHandler:completionHandler];
}
}
@@ -145,7 +141,7 @@
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options {
- if ([_lifeCycleDelegate application:application openURL:url options:options]) {
+ if ([self.lifeCycleDelegate application:application openURL:url options:options]) {
return YES;
}
@@ -178,31 +174,31 @@
}
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {
- return [_lifeCycleDelegate application:application handleOpenURL:url];
+ return [self.lifeCycleDelegate application:application handleOpenURL:url];
}
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
sourceApplication:(NSString*)sourceApplication
annotation:(id)annotation {
- return [_lifeCycleDelegate application:application
- openURL:url
- sourceApplication:sourceApplication
- annotation:annotation];
+ return [self.lifeCycleDelegate application:application
+ openURL:url
+ sourceApplication:sourceApplication
+ annotation:annotation];
}
- (void)application:(UIApplication*)application
performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
completionHandler:(void (^)(BOOL succeeded))completionHandler {
- [_lifeCycleDelegate application:application
- performActionForShortcutItem:shortcutItem
- completionHandler:completionHandler];
+ [self.lifeCycleDelegate application:application
+ performActionForShortcutItem:shortcutItem
+ completionHandler:completionHandler];
}
- (void)application:(UIApplication*)application
handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
completionHandler:(nonnull void (^)())completionHandler {
- [_lifeCycleDelegate application:application
+ [self.lifeCycleDelegate application:application
handleEventsForBackgroundURLSession:identifier
completionHandler:completionHandler];
}
@@ -213,9 +209,9 @@
restorationHandler:
(void (^)(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects))
restorationHandler {
- if ([_lifeCycleDelegate application:application
- continueUserActivity:userActivity
- restorationHandler:restorationHandler]) {
+ if ([self.lifeCycleDelegate application:application
+ continueUserActivity:userActivity
+ restorationHandler:restorationHandler]) {
return YES;
}
@@ -251,30 +247,30 @@
#pragma mark - Selectors handling
- (void)addApplicationLifeCycleDelegate:(NSObject<FlutterApplicationLifeCycleDelegate>*)delegate {
- [_lifeCycleDelegate addDelegate:delegate];
+ [self.lifeCycleDelegate addDelegate:delegate];
}
#pragma mark - UIApplicationDelegate method dynamic implementation
- (BOOL)respondsToSelector:(SEL)selector {
- if ([_lifeCycleDelegate isSelectorAddedDynamically:selector]) {
+ if ([self.lifeCycleDelegate isSelectorAddedDynamically:selector]) {
return [self delegateRespondsSelectorToPlugins:selector];
}
return [super respondsToSelector:selector];
}
- (BOOL)delegateRespondsSelectorToPlugins:(SEL)selector {
- if ([_lifeCycleDelegate hasPluginThatRespondsToSelector:selector]) {
- return [_lifeCycleDelegate respondsToSelector:selector];
+ if ([self.lifeCycleDelegate hasPluginThatRespondsToSelector:selector]) {
+ return [self.lifeCycleDelegate respondsToSelector:selector];
} else {
return NO;
}
}
- (id)forwardingTargetForSelector:(SEL)aSelector {
- if ([_lifeCycleDelegate isSelectorAddedDynamically:aSelector]) {
+ if ([self.lifeCycleDelegate isSelectorAddedDynamically:aSelector]) {
[self logCapabilityConfigurationWarningIfNeeded:aSelector];
- return _lifeCycleDelegate;
+ return self.lifeCycleDelegate;
}
return [super forwardingTargetForSelector:aSelector];
}
@@ -286,7 +282,7 @@
- (void)logCapabilityConfigurationWarningIfNeeded:(SEL)selector {
NSArray* backgroundModesArray =
[[NSBundle mainBundle] objectForInfoDictionaryKey:kUIBackgroundMode];
- NSSet* backgroundModesSet = [[[NSSet alloc] initWithArray:backgroundModesArray] autorelease];
+ NSSet* backgroundModesSet = [[NSSet alloc] initWithArray:backgroundModesArray];
if (selector == @selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)) {
if (![backgroundModesSet containsObject:kRemoteNotificationCapabitiliy]) {
NSLog(