Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e00d405

Browse files
authored
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: flutter/flutter#137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 9c8e5cb commit e00d405

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ source_set("flutter_framework_source_arc") {
5959
public_configs = [ "//flutter:config" ]
6060

6161
sources = [
62+
"framework/Source/FlutterAppDelegate.mm",
6263
"framework/Source/FlutterCallbackCache.mm",
6364
"framework/Source/FlutterCallbackCache_Internal.h",
6465
"framework/Source/FlutterChannelKeyResponder.h",
@@ -179,7 +180,6 @@ source_set("flutter_framework_source") {
179180
# iOS embedder is migrating to ARC.
180181
# New files are highly encouraged to be in ARC.
181182
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
182-
"framework/Source/FlutterAppDelegate.mm",
183183
"framework/Source/FlutterEngine.mm",
184184
"framework/Source/FlutterEngineGroup.mm",
185185
"framework/Source/FlutterEngine_Internal.h",

shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
1212
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate_internal.h"
1313

14+
FLUTTER_ASSERT_ARC
15+
1416
static NSString* const kUIBackgroundMode = @"UIBackgroundModes";
1517
static NSString* const kRemoteNotificationCapabitiliy = @"remote-notification";
1618
static NSString* const kBackgroundFetchCapatibility = @"fetch";
1719
static NSString* const kRestorationStateAppModificationKey = @"mod-date";
1820

1921
@interface FlutterAppDelegate ()
2022
@property(nonatomic, copy) FlutterViewController* (^rootFlutterViewControllerGetter)(void);
23+
@property(nonatomic, strong) FlutterPluginAppLifeCycleDelegate* lifeCycleDelegate;
2124
@end
2225

23-
@implementation FlutterAppDelegate {
24-
FlutterPluginAppLifeCycleDelegate* _lifeCycleDelegate;
25-
}
26+
@implementation FlutterAppDelegate
2627

2728
- (instancetype)init {
2829
if (self = [super init]) {
@@ -31,21 +32,16 @@ - (instancetype)init {
3132
return self;
3233
}
3334

34-
- (void)dealloc {
35-
[_lifeCycleDelegate release];
36-
[_rootFlutterViewControllerGetter release];
37-
[_window release];
38-
[super dealloc];
39-
}
40-
4135
- (BOOL)application:(UIApplication*)application
4236
willFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
43-
return [_lifeCycleDelegate application:application willFinishLaunchingWithOptions:launchOptions];
37+
return [self.lifeCycleDelegate application:application
38+
willFinishLaunchingWithOptions:launchOptions];
4439
}
4540

4641
- (BOOL)application:(UIApplication*)application
4742
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
48-
return [_lifeCycleDelegate application:application didFinishLaunchingWithOptions:launchOptions];
43+
return [self.lifeCycleDelegate application:application
44+
didFinishLaunchingWithOptions:launchOptions];
4945
}
5046

5147
// Returns the key window's rootViewController, if it's a FlutterViewController.
@@ -85,39 +81,39 @@ - (void)applicationWillTerminate:(UIApplication*)application {
8581
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
8682
- (void)application:(UIApplication*)application
8783
didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings {
88-
[_lifeCycleDelegate application:application
84+
[self.lifeCycleDelegate application:application
8985
didRegisterUserNotificationSettings:notificationSettings];
9086
}
9187
#pragma GCC diagnostic pop
9288

9389
- (void)application:(UIApplication*)application
9490
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
95-
[_lifeCycleDelegate application:application
91+
[self.lifeCycleDelegate application:application
9692
didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
9793
}
9894

9995
- (void)application:(UIApplication*)application
10096
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
101-
[_lifeCycleDelegate application:application
97+
[self.lifeCycleDelegate application:application
10298
didFailToRegisterForRemoteNotificationsWithError:error];
10399
}
104100

105101
#pragma GCC diagnostic push
106102
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
107103
- (void)application:(UIApplication*)application
108104
didReceiveLocalNotification:(UILocalNotification*)notification {
109-
[_lifeCycleDelegate application:application didReceiveLocalNotification:notification];
105+
[self.lifeCycleDelegate application:application didReceiveLocalNotification:notification];
110106
}
111107
#pragma GCC diagnostic pop
112108

113109
- (void)userNotificationCenter:(UNUserNotificationCenter*)center
114110
willPresentNotification:(UNNotification*)notification
115111
withCompletionHandler:
116112
(void (^)(UNNotificationPresentationOptions options))completionHandler {
117-
if ([_lifeCycleDelegate respondsToSelector:_cmd]) {
118-
[_lifeCycleDelegate userNotificationCenter:center
119-
willPresentNotification:notification
120-
withCompletionHandler:completionHandler];
113+
if ([self.lifeCycleDelegate respondsToSelector:_cmd]) {
114+
[self.lifeCycleDelegate userNotificationCenter:center
115+
willPresentNotification:notification
116+
withCompletionHandler:completionHandler];
121117
}
122118
}
123119

@@ -127,10 +123,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center
127123
- (void)userNotificationCenter:(UNUserNotificationCenter*)center
128124
didReceiveNotificationResponse:(UNNotificationResponse*)response
129125
withCompletionHandler:(void (^)(void))completionHandler {
130-
if ([_lifeCycleDelegate respondsToSelector:_cmd]) {
131-
[_lifeCycleDelegate userNotificationCenter:center
132-
didReceiveNotificationResponse:response
133-
withCompletionHandler:completionHandler];
126+
if ([self.lifeCycleDelegate respondsToSelector:_cmd]) {
127+
[self.lifeCycleDelegate userNotificationCenter:center
128+
didReceiveNotificationResponse:response
129+
withCompletionHandler:completionHandler];
134130
}
135131
}
136132

@@ -145,7 +141,7 @@ - (BOOL)isFlutterDeepLinkingEnabled {
145141
- (BOOL)application:(UIApplication*)application
146142
openURL:(NSURL*)url
147143
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options {
148-
if ([_lifeCycleDelegate application:application openURL:url options:options]) {
144+
if ([self.lifeCycleDelegate application:application openURL:url options:options]) {
149145
return YES;
150146
}
151147

@@ -178,31 +174,31 @@ - (BOOL)handleOpenURL:(NSURL*)url
178174
}
179175

180176
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {
181-
return [_lifeCycleDelegate application:application handleOpenURL:url];
177+
return [self.lifeCycleDelegate application:application handleOpenURL:url];
182178
}
183179

184180
- (BOOL)application:(UIApplication*)application
185181
openURL:(NSURL*)url
186182
sourceApplication:(NSString*)sourceApplication
187183
annotation:(id)annotation {
188-
return [_lifeCycleDelegate application:application
189-
openURL:url
190-
sourceApplication:sourceApplication
191-
annotation:annotation];
184+
return [self.lifeCycleDelegate application:application
185+
openURL:url
186+
sourceApplication:sourceApplication
187+
annotation:annotation];
192188
}
193189

194190
- (void)application:(UIApplication*)application
195191
performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
196192
completionHandler:(void (^)(BOOL succeeded))completionHandler {
197-
[_lifeCycleDelegate application:application
198-
performActionForShortcutItem:shortcutItem
199-
completionHandler:completionHandler];
193+
[self.lifeCycleDelegate application:application
194+
performActionForShortcutItem:shortcutItem
195+
completionHandler:completionHandler];
200196
}
201197

202198
- (void)application:(UIApplication*)application
203199
handleEventsForBackgroundURLSession:(nonnull NSString*)identifier
204200
completionHandler:(nonnull void (^)())completionHandler {
205-
[_lifeCycleDelegate application:application
201+
[self.lifeCycleDelegate application:application
206202
handleEventsForBackgroundURLSession:identifier
207203
completionHandler:completionHandler];
208204
}
@@ -213,9 +209,9 @@ - (BOOL)application:(UIApplication*)application
213209
restorationHandler:
214210
(void (^)(NSArray<id<UIUserActivityRestoring>>* __nullable restorableObjects))
215211
restorationHandler {
216-
if ([_lifeCycleDelegate application:application
217-
continueUserActivity:userActivity
218-
restorationHandler:restorationHandler]) {
212+
if ([self.lifeCycleDelegate application:application
213+
continueUserActivity:userActivity
214+
restorationHandler:restorationHandler]) {
219215
return YES;
220216
}
221217

@@ -251,30 +247,30 @@ - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
251247
#pragma mark - Selectors handling
252248

253249
- (void)addApplicationLifeCycleDelegate:(NSObject<FlutterApplicationLifeCycleDelegate>*)delegate {
254-
[_lifeCycleDelegate addDelegate:delegate];
250+
[self.lifeCycleDelegate addDelegate:delegate];
255251
}
256252

257253
#pragma mark - UIApplicationDelegate method dynamic implementation
258254

259255
- (BOOL)respondsToSelector:(SEL)selector {
260-
if ([_lifeCycleDelegate isSelectorAddedDynamically:selector]) {
256+
if ([self.lifeCycleDelegate isSelectorAddedDynamically:selector]) {
261257
return [self delegateRespondsSelectorToPlugins:selector];
262258
}
263259
return [super respondsToSelector:selector];
264260
}
265261

266262
- (BOOL)delegateRespondsSelectorToPlugins:(SEL)selector {
267-
if ([_lifeCycleDelegate hasPluginThatRespondsToSelector:selector]) {
268-
return [_lifeCycleDelegate respondsToSelector:selector];
263+
if ([self.lifeCycleDelegate hasPluginThatRespondsToSelector:selector]) {
264+
return [self.lifeCycleDelegate respondsToSelector:selector];
269265
} else {
270266
return NO;
271267
}
272268
}
273269

274270
- (id)forwardingTargetForSelector:(SEL)aSelector {
275-
if ([_lifeCycleDelegate isSelectorAddedDynamically:aSelector]) {
271+
if ([self.lifeCycleDelegate isSelectorAddedDynamically:aSelector]) {
276272
[self logCapabilityConfigurationWarningIfNeeded:aSelector];
277-
return _lifeCycleDelegate;
273+
return self.lifeCycleDelegate;
278274
}
279275
return [super forwardingTargetForSelector:aSelector];
280276
}
@@ -286,7 +282,7 @@ - (id)forwardingTargetForSelector:(SEL)aSelector {
286282
- (void)logCapabilityConfigurationWarningIfNeeded:(SEL)selector {
287283
NSArray* backgroundModesArray =
288284
[[NSBundle mainBundle] objectForInfoDictionaryKey:kUIBackgroundMode];
289-
NSSet* backgroundModesSet = [[[NSSet alloc] initWithArray:backgroundModesArray] autorelease];
285+
NSSet* backgroundModesSet = [[NSSet alloc] initWithArray:backgroundModesArray];
290286
if (selector == @selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)) {
291287
if (![backgroundModesSet containsObject:kRemoteNotificationCapabitiliy]) {
292288
NSLog(

0 commit comments

Comments
 (0)