-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Remote notification completion handler #8040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
JAStanton
wants to merge
19
commits into
facebook:master
from
convoyinc-deprecated:remote-notification-completion-handler
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4c56ed8
js side
JAStanton 8f7d228
Add finish completion handler for remote notifications
JAStanton 634fa53
update documentation
JAStanton 7bfdcd2
track isRemote
JAStanton 7168a86
add notificationID and isRemote to documention of class
JAStanton 6a76e04
Merge branch 'master' into remote-notification-completion-handler
JAStanton a3a2a1b
Merge branch 'master' into remote-notification-completion-handler
JAStanton b1266ee
rebase and rely on the remote property of notifications
JAStanton 5095708
pr feedback / cleanup
JAStanton c59a013
add this back in
JAStanton 5414373
Merge branch 'master' into remote-notification-completion-handler
JAStanton 1d303c0
confirmed not needed
JAStanton 734ef97
fix flow
JAStanton db74ec8
static wasnt happy with site code gen
JAStanton 622e944
Merge commit 'ae9cc00' into remote-notification-completion-handler
JAStanton 526dabc
potentially fix flow again
JAStanton 1e39c3e
Merge branch 'master' into remote-notification-completion-handler
JAStanton 6a695eb
Merge commit '942f724' into remote-notification-completion-handler
JAStanton 615614a
RCTLogError already handled interpolation
JAStanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,10 @@ @implementation RCTConvert (NSCalendarUnit) | |
|
|
||
| @end | ||
|
|
||
| @interface RCTPushNotificationManager () | ||
| @property (nonatomic, strong) NSMutableDictionary *remoteNotificationCallbacks; | ||
| @end | ||
|
|
||
| @implementation RCTConvert (UILocalNotification) | ||
|
|
||
| + (UILocalNotification *)UILocalNotification:(id)json | ||
|
|
@@ -58,6 +62,12 @@ + (UILocalNotification *)UILocalNotification:(id)json | |
| return notification; | ||
| } | ||
|
|
||
| RCT_ENUM_CONVERTER(UIBackgroundFetchResult, (@{ | ||
| @"UIBackgroundFetchResultNewData": @(UIBackgroundFetchResultNewData), | ||
| @"UIBackgroundFetchResultNoData": @(UIBackgroundFetchResultNoData), | ||
| @"UIBackgroundFetchResultFailed": @(UIBackgroundFetchResultFailed), | ||
| }), UIBackgroundFetchResultNoData, integerValue) | ||
|
|
||
| @end | ||
| #endif //TARGET_OS_TV | ||
|
|
||
|
|
@@ -167,9 +177,19 @@ + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error | |
|
|
||
| + (void)didReceiveRemoteNotification:(NSDictionary *)notification | ||
| { | ||
| NSDictionary *userInfo = @{@"notification": notification}; | ||
| [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived | ||
| object:self | ||
| userInfo:userInfo]; | ||
| } | ||
|
|
||
| + (void)didReceiveRemoteNotification:(NSDictionary *)notification | ||
| fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler | ||
| { | ||
| NSDictionary *userInfo = @{@"notification": notification, @"completionHandler": completionHandler}; | ||
| [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived | ||
| object:self | ||
| userInfo:notification]; | ||
| userInfo:userInfo]; | ||
| } | ||
|
|
||
| + (void)didReceiveLocalNotification:(UILocalNotification *)notification | ||
|
|
@@ -186,9 +206,20 @@ - (void)handleLocalNotificationReceived:(NSNotification *)notification | |
|
|
||
| - (void)handleRemoteNotificationReceived:(NSNotification *)notification | ||
| { | ||
| NSMutableDictionary *userInfo = [notification.userInfo mutableCopy]; | ||
| userInfo[@"remote"] = @YES; | ||
| [self sendEventWithName:@"remoteNotificationReceived" body:userInfo]; | ||
| NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:notification.userInfo[@"notification"]]; | ||
| RCTRemoteNotificationCallback completionHandler = notification.userInfo[@"completionHandler"]; | ||
| NSString* notificationId = [[NSUUID UUID] UUIDString]; | ||
| remoteNotification[@"notificationId"] = notificationId; | ||
| remoteNotification[@"remote"] = @YES; | ||
| if (completionHandler) { | ||
| if (!self.remoteNotificationCallbacks) { | ||
| // Lazy initialization | ||
| self.remoteNotificationCallbacks = [NSMutableDictionary dictionary]; | ||
| } | ||
| self.remoteNotificationCallbacks[notificationId] = completionHandler; | ||
| } | ||
|
|
||
| [self sendEventWithName:@"remoteNotificationReceived" body:notification.userInfo]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you sending the event twice?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops! Bad merge |
||
| } | ||
|
|
||
| - (void)handleRemoteNotificationsRegistered:(NSNotification *)notification | ||
|
|
@@ -224,6 +255,16 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification | |
| _requestPermissionsResolveBlock = nil; | ||
| } | ||
|
|
||
| RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString*)notificationId fetchResult:(UIBackgroundFetchResult)result) { | ||
| RCTRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId]; | ||
| if (!completionHandler) { | ||
| RCTLogError(@"There is no completion handler with notification id: %@", notificationId) | ||
| return; | ||
| } | ||
| completionHandler(result); | ||
| [self.remoteNotificationCallbacks removeObjectForKey:notificationId]; | ||
| } | ||
|
|
||
| /** | ||
| * Update the application icon badge number on the home screen | ||
| */ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FetchResult type referenced from value position type FetchResult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property
FetchResultProperty not found in statics of PushNotificationIOS