diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-01-26 22:00:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 22:00:11 +0100 |
commit | 1cfa1b48f9e66e4304608ab5110cc87927c2f2a6 (patch) | |
tree | 736650d745c4cde73530c42b9171e32c685bbcef | |
parent | fa498f6105bb18a038210f4c000e1a97b7c86354 (diff) | |
parent | 366ce084f494be06e7c6d166c6e4688c2db7dd7a (diff) |
Merge pull request #45484 from naithar/fix/ios-push-notification
[iOS] Rework/Fix APNS usage.
-rw-r--r-- | platform/iphone/godot_app_delegate.h | 24 | ||||
-rw-r--r-- | 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 6335ada50e..76d8aa409f 100644 --- a/platform/iphone/godot_app_delegate.h +++ b/platform/iphone/godot_app_delegate.h @@ -31,6 +31,7 @@ #import <UIKit/UIKit.h> typedef NSObject<UIApplicationDelegate> ApplicationDelegateService; +typedef void (^APNSNotification)(UIBackgroundFetchResult); @interface GodotApplicalitionDelegate : NSObject <UIApplicationDelegate> @@ -38,4 +39,27 @@ typedef NSObject<UIApplicationDelegate> 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 7b9cf7893c..9d298162f3 100644 --- a/platform/iphone/godot_app_delegate.m +++ b/platform/iphone/godot_app_delegate.m @@ -302,7 +302,7 @@ static NSMutableArray<ApplicationDelegateService *> *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<ApplicationDelegateService *> *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<ApplicationDelegateService *> *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; |