Skip to content

Commit c30425e

Browse files
Handling local notification event for IOS 10+ (#104)
1 parent aed903f commit c30425e

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,20 @@ fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
102102
{
103103
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
104104
}
105-
// Required for the localNotification event.
105+
// IOS 10+ Required for localNotification event
106+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
107+
didReceiveNotificationResponse:(UNNotificationResponse *)response
108+
withCompletionHandler:(void (^)(void))completionHandler
109+
{
110+
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
111+
completionHandler();
112+
}
113+
// IOS 4-10 Required for the localNotification event.
106114
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
107115
{
108116
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
109117
}
118+
110119
```
111120

112121
Also, if not already present, at the top of the file:

example/ios/example/AppDelegate.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UI
6969
{
7070
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
7171
}
72+
// IOS 10+ Required for local notification tapped event
73+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
74+
didReceiveNotificationResponse:(UNNotificationResponse *)response
75+
withCompletionHandler:(void (^)(void))completionHandler
76+
{
77+
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
78+
completionHandler();
79+
}
7280

7381
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
7482
{

ios/RNCPushNotificationIOS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef void (^RNCRemoteNotificationCallback)(UIBackgroundFetchResult result);
1919
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
2020
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(RNCRemoteNotificationCallback)completionHandler;
2121
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification;
22+
+ (void)didReceiveNotificationResponse:(UNNotificationResponse *)response API_AVAILABLE(ios(10.0));
2223
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
2324
#endif
2425

ios/RNCPushNotificationIOS.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ + (void)didReceiveLocalNotification:(UILocalNotification *)notification
216216
userInfo:RCTFormatLocalNotification(notification)];
217217
}
218218

219+
+ (void)didReceiveNotificationResponse:(UNNotificationResponse *)response
220+
API_AVAILABLE(ios(10.0)) {
221+
[[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
222+
object:self
223+
userInfo:RCTFormatUNNotification(response.notification)];
224+
}
225+
219226
- (void)handleLocalNotificationReceived:(NSNotification *)notification
220227
{
221228
[self sendEventWithName:@"localNotificationReceived" body:notification.userInfo];

0 commit comments

Comments
 (0)