diff --git a/packages/messaging/ios/RNFBMessaging.xcodeproj/project.pbxproj b/packages/messaging/ios/RNFBMessaging.xcodeproj/project.pbxproj index 50905da960..8e3c7f8850 100644 --- a/packages/messaging/ios/RNFBMessaging.xcodeproj/project.pbxproj +++ b/packages/messaging/ios/RNFBMessaging.xcodeproj/project.pbxproj @@ -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 */ @@ -39,6 +40,8 @@ 27F24645242AA30E0098906C /* RNFBMessaging+FIRMessagingDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNFBMessaging+FIRMessagingDelegate.m"; sourceTree = ""; }; 27F2464B242AA7330098906C /* RNFBMessaging+NSNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNFBMessaging+NSNotificationCenter.h"; sourceTree = ""; }; 27F2464C242AA7330098906C /* RNFBMessaging+NSNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNFBMessaging+NSNotificationCenter.m"; sourceTree = ""; }; + 37D60F7124E6465300E44930 /* RNFBMessaging+UNNotificationServiceExtension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNFBMessaging+UNNotificationServiceExtension.h"; sourceTree = ""; }; + 37D60F7324E647BF00E44930 /* RNFBMessaging+UNNotificationServiceExtension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNFBMessaging+UNNotificationServiceExtension.m"; sourceTree = ""; }; DA446E5022CA485C0066A0A3 /* RNFBMessagingSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFBMessagingSerializer.h; sourceTree = ""; }; DA446E5122CA48690066A0A3 /* RNFBMessagingSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNFBMessagingSerializer.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -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 */, @@ -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 */, diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNNotificationServiceExtension.h b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNNotificationServiceExtension.h new file mode 100644 index 0000000000..32925d598d --- /dev/null +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNNotificationServiceExtension.h @@ -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 + +@interface RNFBMessagingNotificationServiceExtension : UNNotificationServiceExtension + +@end /* RNFBMessaging_UNNotificationServiceExtension_h */ diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNNotificationServiceExtension.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNNotificationServiceExtension.m new file mode 100644 index 0000000000..aabc137733 --- /dev/null +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+UNNotificationServiceExtension.m @@ -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)) +@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