From 9c5557e8f7b07ac691ea4516078147e580f6c85a Mon Sep 17 00:00:00 2001 From: Ben Butterworth <24711048+ben-xD@users.noreply.github.com> Date: Tue, 9 Nov 2021 20:58:01 +0000 Subject: [PATCH] Call `didFailToRegisterForRemoteNotificationsWithError` delegate methods in `FlutterPlugin` (flutter/engine#28609) --- .../darwin/ios/framework/Headers/FlutterPlugin.h | 6 ++++++ .../Headers/FlutterPluginAppLifeCycleDelegate.h | 6 ++++++ .../ios/framework/Source/FlutterAppDelegate.mm | 6 ++++++ .../Source/FlutterPluginAppLifeCycleDelegate.mm | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 783c6a35f1..8b212c3e4d 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -83,6 +83,12 @@ NS_ASSUME_NONNULL_BEGIN - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken; +/** + * Called if this has been registered for `UIApplicationDelegate` callbacks. + */ +- (void)application:(UIApplication*)application + didFailToRegisterForRemoteNotificationsWithError:(NSError*)error; + /** * Called if this has been registered for `UIApplicationDelegate` callbacks. * diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h index 3d7d090c2c..dd6489c6f6 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h @@ -57,6 +57,12 @@ FLUTTER_DARWIN_EXPORT - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken; +/** + * Calls all plugins registered for `UIApplicationDelegate` callbacks. + */ +- (void)application:(UIApplication*)application + didFailToRegisterForRemoteNotificationsWithError:(NSError*)error; + /** * Calls all plugins registered for `UIApplicationDelegate` callbacks. */ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index fa68266619..44b2800ce5 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -95,6 +95,12 @@ static NSString* const kRestorationStateAppModificationKey = @"mod-date"; didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } +- (void)application:(UIApplication*)application + didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { + [_lifeCycleDelegate application:application + didFailToRegisterForRemoteNotificationsWithError:error]; +} + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" - (void)application:(UIApplication*)application diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm index 424d1eaeff..9d5b02856d 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm @@ -248,6 +248,18 @@ static BOOL isPowerOfTwo(NSUInteger x) { } } +- (void)application:(UIApplication*)application + didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { + for (NSObject* delegate in _delegates) { + if (!delegate) { + continue; + } + if ([delegate respondsToSelector:_cmd]) { + [delegate application:application didFailToRegisterForRemoteNotificationsWithError:error]; + } + } +} + - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {