[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.
This commit is contained in:
Sergey Minakov 2021-01-26 18:35:48 +03:00
parent 6bea301533
commit 366ce084f4
2 changed files with 27 additions and 3 deletions

View file

@ -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

View file

@ -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;