Skip to content

Commit

Permalink
iOS: Migrate FlutterAppDelegate to ARC (#55472)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cbracken authored Sep 27, 2024
1 parent 9c8e5cb commit e00d405
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ source_set("flutter_framework_source_arc") {
public_configs = [ "//flutter:config" ]

sources = [
"framework/Source/FlutterAppDelegate.mm",
"framework/Source/FlutterCallbackCache.mm",
"framework/Source/FlutterCallbackCache_Internal.h",
"framework/Source/FlutterChannelKeyResponder.h",
Expand Down Expand Up @@ -179,7 +180,6 @@ source_set("flutter_framework_source") {
# 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",
Expand Down
84 changes: 40 additions & 44 deletions shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
#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";
static NSString* const kRestorationStateAppModificationKey = @"mod-date";

@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]) {
Expand All @@ -31,21 +32,16 @@ - (instancetype)init {
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.
Expand Down Expand Up @@ -85,39 +81,39 @@ - (void)applicationWillTerminate:(UIApplication*)application {
#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];
}

#pragma GCC diagnostic push
#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

- (void)userNotificationCenter:(UNUserNotificationCenter*)center
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];
}
}

Expand All @@ -127,10 +123,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center
- (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];
}
}

Expand All @@ -145,7 +141,7 @@ - (BOOL)isFlutterDeepLinkingEnabled {
- (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;
}

Expand Down Expand Up @@ -178,31 +174,31 @@ - (BOOL)handleOpenURL:(NSURL*)url
}

- (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];
}
Expand All @@ -213,9 +209,9 @@ - (BOOL)application:(UIApplication*)application
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;
}

Expand Down Expand Up @@ -251,30 +247,30 @@ - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
#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];
}
Expand All @@ -286,7 +282,7 @@ - (id)forwardingTargetForSelector:(SEL)aSelector {
- (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(
Expand Down

0 comments on commit e00d405

Please sign in to comment.