From d2af815039060063524633cb7028e2f005c2685b Mon Sep 17 00:00:00 2001 From: Sergey Minakov Date: Tue, 26 Jan 2021 18:35:48 +0300 Subject: [PATCH] [iOS] Rework push notification methods usage Moved AppDelegate push notifications methods implementation to 'GODOT_ENABLE_PUSH_NOTIFICATIONS' which can be used in plugins to implement APNS plugins. (cherry picked from commit 366ce084f494be06e7c6d166c6e4688c2db7dd7a) --- platform/iphone/godot_app_delegate.h | 24 ++++++++++++++++++++++++ platform/iphone/godot_app_delegate.m | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/platform/iphone/godot_app_delegate.h b/platform/iphone/godot_app_delegate.h index 6335ada50eb..76d8aa409fd 100644 --- a/platform/iphone/godot_app_delegate.h +++ b/platform/iphone/godot_app_delegate.h @@ -31,6 +31,7 @@ #import typedef NSObject ApplicationDelegateService; +typedef void (^APNSNotification)(UIBackgroundFetchResult); @interface GodotApplicalitionDelegate : NSObject @@ -38,4 +39,27 @@ typedef NSObject ApplicationDelegateService; + (void)addService:(ApplicationDelegateService *)service; +- (void)godot:(UIApplication *)application receivedNotificationToken:(NSData *)deviceToken; +- (void)godot:(UIApplication *)application receivedNotificationError:(NSError *)error; +- (void)godot:(UIApplication *)application receivedNotification:(NSDictionary *)userInfo completion:(APNSNotification)completionHandler; + @end + +#define GODOT_ENABLE_PUSH_NOTIFICATIONS \ + @interface GodotApplicalitionDelegate (PushNotifications) \ + @end \ + @implementation GodotApplicalitionDelegate (PushNotifications) \ + -(void)application : (UIApplication *)application \ + didRegisterForRemoteNotificationsWithDeviceToken : (NSData *)deviceToken { \ + [self godot:application receivedNotificationToken:deviceToken]; \ + } \ + -(void)application : (UIApplication *)application \ + didFailToRegisterForRemoteNotificationsWithError : (NSError *)error { \ + [self godot:application receivedNotificationError:error]; \ + } \ + -(void)application : (UIApplication *)application \ + didReceiveRemoteNotification : (NSDictionary *)userInfo \ + fetchCompletionHandler : (APNSNotification)completionHandler { \ + [self godot:application receivedNotification:userInfo completion:completionHandler]; \ + } \ + @end diff --git a/platform/iphone/godot_app_delegate.m b/platform/iphone/godot_app_delegate.m index 2c9029aa640..b416c51457b 100644 --- a/platform/iphone/godot_app_delegate.m +++ b/platform/iphone/godot_app_delegate.m @@ -302,7 +302,7 @@ static NSMutableArray *services = nil; // MARK: Remote Notification -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { +- (void)godot:(UIApplication *)application receivedNotificationToken:(NSData *)deviceToken { for (ApplicationDelegateService *service in services) { if (![service respondsToSelector:_cmd]) { continue; @@ -312,7 +312,7 @@ static NSMutableArray *services = nil; } } -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { +- (void)godot:(UIApplication *)application receivedNotificationError:(NSError *)error { for (ApplicationDelegateService *service in services) { if (![service respondsToSelector:_cmd]) { continue; @@ -322,7 +322,7 @@ static NSMutableArray *services = nil; } } -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { +- (void)godot:(UIApplication *)application receivedNotification:(NSDictionary *)userInfo completion:(APNSNotification)completionHandler { for (ApplicationDelegateService *service in services) { if (![service respondsToSelector:_cmd]) { continue;