From ae18b0ef6bbc28bbfc659edee319ebc81044ca97 Mon Sep 17 00:00:00 2001 From: Muhammad Date: Thu, 28 Feb 2019 17:26:45 +0200 Subject: [PATCH] fixes --- RNNotifications/RNNRouter.h | 6 +- RNNotifications/RNNRouter.m | 17 +++--- RNNotifications/RNNotifications.h | 2 +- RNNotifications/RNNotifications.m | 2 +- .../contents.xcworkspacedata | 3 + .../ios/NotificationsExampleApp/AppDelegate.h | 3 +- .../ios/NotificationsExampleApp/AppDelegate.m | 60 ++++++++++++------- example/package.json | 2 +- 8 files changed, 58 insertions(+), 37 deletions(-) diff --git a/RNNotifications/RNNRouter.h b/RNNotifications/RNNRouter.h index 5874e39..049280f 100644 --- a/RNNotifications/RNNRouter.h +++ b/RNNotifications/RNNRouter.h @@ -17,7 +17,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler; - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler; -- (void)handlePushKitRegistered:(NSNotification *)notification; +- (void)handlePushKitRegistered:(NSDictionary *)notification; @end @@ -29,9 +29,11 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nullable void (^)(UIBackgroundFetchResult))completionHandler; - (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type; - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type; +- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler; +- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler; diff --git a/RNNotifications/RNNRouter.m b/RNNotifications/RNNRouter.m index 8aa7306..d81e9b3 100644 --- a/RNNotifications/RNNRouter.m +++ b/RNNotifications/RNNRouter.m @@ -7,7 +7,7 @@ // #import "RNNRouter.h" - +#import "RNNotifications.h" //RNNNotifications's router (delegater) ::: singleton which routes all the static, system functions delegate calls to RNNNotifications insatnce ; can't have and RNNNotifications instance from outside of it's class @@ -22,7 +22,7 @@ @implementation RNNRouter + (nonnull instancetype)sharedInstance -{ +/Users/muhammadr/Desktop/Production/RNNotifions/react-native-notifications/example/node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj{ static RNNRouter* sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -105,11 +105,6 @@ } } - -///////////////////////////////////////////////////////////////// -#pragma mark static calls for RNNNotifications rerouting purpous functions -//////////////////////////////////////////////////////////////// - - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { if (self.delegate != nil) @@ -139,14 +134,16 @@ { if(self.delegate != nil) { - // [self.delegate handlePushKitRegistered:@{@"pushKitToken": [RNNotifications deviceTokenToString:credentials.token]}]; + [self.delegate handlePushKitRegistered:@{@"pushKitToken": [RNNotifications deviceTokenToString:credentials.token]}]; } } - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { - //TODO: check here - // [RNNotifications didReceiveRemoteNotification:payload.dictionaryPayload]; + if (self.delegate != nil) + { + [self.delegate application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil]; + } } @end diff --git a/RNNotifications/RNNotifications.h b/RNNotifications/RNNotifications.h index c13433e..3c6dbb0 100644 --- a/RNNotifications/RNNotifications.h +++ b/RNNotifications/RNNotifications.h @@ -7,5 +7,5 @@ @interface RNNotifications : RCTEventEmitter - ++ (NSString *)deviceTokenToString:(NSData *)deviceToken; @end diff --git a/RNNotifications/RNNotifications.m b/RNNotifications/RNNotifications.m index eadba86..a50a24f 100644 --- a/RNNotifications/RNNotifications.m +++ b/RNNotifications/RNNotifications.m @@ -295,7 +295,7 @@ RCT_EXPORT_MODULE() } } -- (void)handlePushKitRegistered:(NSNotification *)notification +- (void)handlePushKitRegistered:(NSDictionary *)notification { [self checkAndSendEvent:RNPushKitRegistered body:notification]; } diff --git a/RNNotifications/RNNotifications.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RNNotifications/RNNotifications.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 94b2795..919434a 100644 --- a/RNNotifications/RNNotifications.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/RNNotifications/RNNotifications.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -1,4 +1,7 @@ + + diff --git a/example/ios/NotificationsExampleApp/AppDelegate.h b/example/ios/NotificationsExampleApp/AppDelegate.h index 1f29849..62190c8 100644 --- a/example/ios/NotificationsExampleApp/AppDelegate.h +++ b/example/ios/NotificationsExampleApp/AppDelegate.h @@ -10,8 +10,9 @@ #import #import +@import UserNotifications; -@interface AppDelegate : UIResponder +@interface AppDelegate : UIResponder @property (nonatomic, strong) UIWindow *window; diff --git a/example/ios/NotificationsExampleApp/AppDelegate.m b/example/ios/NotificationsExampleApp/AppDelegate.m index 1c5cbc7..fe7c428 100644 --- a/example/ios/NotificationsExampleApp/AppDelegate.m +++ b/example/ios/NotificationsExampleApp/AppDelegate.m @@ -12,7 +12,7 @@ #import "RCTBundleURLProvider.h" #import "RCTRootView.h" #import "RNNotifications.h" - +#import "RNNRouter.h" #import @implementation AppDelegate @@ -40,48 +40,66 @@ // PushKit API Example - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type { - [RNNotifications didUpdatePushCredentials:credentials forType:type]; + [[RNNRouter sharedInstance] didUpdatePushCredentials:credentials forType:type]; } + - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { - [RNNotifications didReceiveRemoteNotification:payload.dictionaryPayload]; + [[RNNRouter sharedInstance] application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil]; } - -// Required to register for notifications -- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings +- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - [RNNotifications didRegisterUserNotificationSettings:notificationSettings]; + [[RNNRouter sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error]; } +//// Required to register for notifications +//- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings +//{ +// [RNNotifications didRegisterUserNotificationSettings:notificationSettings]; +//} + - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; + [[RNNRouter sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { - [RNNotifications didReceiveRemoteNotification:notification]; -} - -// Required for the localNotification event. -- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { - [RNNotifications didReceiveLocalNotification:notification]; + [[RNNRouter sharedInstance] application:application didReceiveRemoteNotification:notification fetchCompletionHandler:nil]; } - -// Required for the notification actions. -- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler +- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { - [RNNotifications handleActionWithIdentifier:identifier forLocalNotification:notification withResponseInfo:responseInfo completionHandler:completionHandler]; + [[RNNRouter sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; } -- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler +- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { - [RNNotifications handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo completionHandler:completionHandler]; + [[RNNRouter sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; } + + +//// Required for the localNotification event. +//- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification +//{ +// [RNNotifications didReceiveLocalNotification:notification]; +//} + + +//// Required for the notification actions. +//- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler +//{ +// [RNNotifications handleActionWithIdentifier:identifier forLocalNotification:notification withResponseInfo:responseInfo completionHandler:completionHandler]; +//} +// +//- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler +//{ +// [RNNotifications handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo completionHandler:completionHandler]; +//} + @end diff --git a/example/package.json b/example/package.json index 9997eee..ab19508 100644 --- a/example/package.json +++ b/example/package.json @@ -8,6 +8,6 @@ "dependencies": { "react": "16.6.0-alpha.8af6728", "react-native": "^0.57.4", - "react-native-notifications": "latest" + "react-native-notifications": "git://github.com/wix/react-native-notifications.git#iosDeprecationsFixes" } }