Skip to content
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

feat(messaging,ios): add notification extension service to support im… #4085

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
27F24643242AA2EE0098906C /* RNFBMessaging+AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F24642242AA2EE0098906C /* RNFBMessaging+AppDelegate.m */; };
27F24646242AA30E0098906C /* RNFBMessaging+FIRMessagingDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F24645242AA30E0098906C /* RNFBMessaging+FIRMessagingDelegate.m */; };
27F2464D242AA7330098906C /* RNFBMessaging+NSNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F2464C242AA7330098906C /* RNFBMessaging+NSNotificationCenter.m */; };
37D60F7424E647BF00E44930 /* RNFBMessaging+UNNotificationServiceExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 37D60F7324E647BF00E44930 /* RNFBMessaging+UNNotificationServiceExtension.m */; };
DA446E5222CA48690066A0A3 /* RNFBMessagingSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = DA446E5122CA48690066A0A3 /* RNFBMessagingSerializer.m */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -39,6 +40,8 @@
27F24645242AA30E0098906C /* RNFBMessaging+FIRMessagingDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNFBMessaging+FIRMessagingDelegate.m"; sourceTree = "<group>"; };
27F2464B242AA7330098906C /* RNFBMessaging+NSNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNFBMessaging+NSNotificationCenter.h"; sourceTree = "<group>"; };
27F2464C242AA7330098906C /* RNFBMessaging+NSNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNFBMessaging+NSNotificationCenter.m"; sourceTree = "<group>"; };
37D60F7124E6465300E44930 /* RNFBMessaging+UNNotificationServiceExtension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNFBMessaging+UNNotificationServiceExtension.h"; sourceTree = "<group>"; };
37D60F7324E647BF00E44930 /* RNFBMessaging+UNNotificationServiceExtension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNFBMessaging+UNNotificationServiceExtension.m"; sourceTree = "<group>"; };
DA446E5022CA485C0066A0A3 /* RNFBMessagingSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFBMessagingSerializer.h; sourceTree = "<group>"; };
DA446E5122CA48690066A0A3 /* RNFBMessagingSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNFBMessagingSerializer.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -65,6 +68,8 @@
2744B98321F45429004F8E3F /* RNFBMessaging */ = {
isa = PBXGroup;
children = (
37D60F7324E647BF00E44930 /* RNFBMessaging+UNNotificationServiceExtension.m */,
37D60F7124E6465300E44930 /* RNFBMessaging+UNNotificationServiceExtension.h */,
2744B98421F45429004F8E3F /* RNFBMessagingModule.h */,
2744B98521F45429004F8E3F /* RNFBMessagingModule.m */,
DA446E5022CA485C0066A0A3 /* RNFBMessagingSerializer.h */,
Expand Down Expand Up @@ -150,6 +155,7 @@
files = (
2744B98621F45429004F8E3F /* RNFBMessagingModule.m in Sources */,
27F24643242AA2EE0098906C /* RNFBMessaging+AppDelegate.m in Sources */,
37D60F7424E647BF00E44930 /* RNFBMessaging+UNNotificationServiceExtension.m in Sources */,
27F24640242AA29F0098906C /* RNFBMessaging+UNUserNotificationCenter.m in Sources */,
DA446E5222CA48690066A0A3 /* RNFBMessagingSerializer.m in Sources */,
27F2464D242AA7330098906C /* RNFBMessaging+NSNotificationCenter.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#import <UserNotifications/UserNotifications.h>

@interface RNFBMessagingNotificationServiceExtension : UNNotificationServiceExtension

@end /* RNFBMessaging_UNNotificationServiceExtension_h */
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#import "RNFBMessaging+UNNotificationServiceExtension.h"
#import "FirebaseMessaging.h"

API_AVAILABLE(ios(10.0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - I had thought RNFB moved to iOS10 as a minimum but it still supports 9 right now: https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/RNFBMessaging.podspec#L28 - it's Notifee and React-Native itself (with version 0.63) that have moved to 10 already

@interface RNFBMessagingNotificationServiceExtension ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation RNFBMessagingNotificationServiceExtension

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler API_AVAILABLE(ios(10.0)) API_AVAILABLE(ios(10.0)){
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];

if (@available(iOS 10.0, *)) {
[[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];
} else {
// Fallback on earlier versions
self.contentHandler(self.bestAttemptContent);
}
}

- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
self.contentHandler(self.bestAttemptContent);
}

@end