diff --git a/ios/RNFirebase.xcodeproj/project.pbxproj b/ios/RNFirebase.xcodeproj/project.pbxproj index 88370b00..4ed4efc0 100644 --- a/ios/RNFirebase.xcodeproj/project.pbxproj +++ b/ios/RNFirebase.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 168785AD210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 168785AB210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m */; }; 17AF4F6B1F59CDBF00C02336 /* RNFirebaseLinks.m in Sources */ = {isa = PBXBuildFile; fileRef = 17AF4F6A1F59CDBF00C02336 /* RNFirebaseLinks.m */; }; 27540F9A209F3641001F4AF4 /* RNFirebaseFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 27540F99209F3641001F4AF4 /* RNFirebaseFunctions.m */; }; 8300A7AE1F31E143001B16AB /* RNFirebaseDatabaseReference.m in Sources */ = {isa = PBXBuildFile; fileRef = 8300A7AD1F31E143001B16AB /* RNFirebaseDatabaseReference.m */; }; @@ -50,6 +51,8 @@ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRNFirebase.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFirebase.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 168785AB210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+UIBackgroundFetchResult.m"; sourceTree = ""; }; + 168785AC210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIBackgroundFetchResult.h"; sourceTree = ""; }; 17AF4F691F59CDBF00C02336 /* RNFirebaseLinks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNFirebaseLinks.h; sourceTree = ""; }; 17AF4F6A1F59CDBF00C02336 /* RNFirebaseLinks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFirebaseLinks.m; sourceTree = ""; }; 27540F98209F361B001F4AF4 /* RNFirebaseFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFirebaseFunctions.h; sourceTree = ""; }; @@ -126,6 +129,16 @@ name = Products; sourceTree = ""; }; + 168785A0210B50AA00E4BD57 /* converters */ = { + isa = PBXGroup; + children = ( + 168785AC210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.h */, + 168785AB210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m */, + ); + name = converters; + path = RNFirebase/converters; + sourceTree = ""; + }; 17AF4F681F59CDBF00C02336 /* links */ = { isa = PBXGroup; children = ( @@ -149,6 +162,7 @@ 58B511D21A9E6C8500147676 = { isa = PBXGroup; children = ( + 168785A0210B50AA00E4BD57 /* converters */, 27540F97209F35DF001F4AF4 /* functions */, 83AAA0762063DEC2007EC5F7 /* invites */, 838E372420231E15004DCD3A /* notifications */, @@ -398,6 +412,7 @@ 27540F9A209F3641001F4AF4 /* RNFirebaseFunctions.m in Sources */, 838E372320231DF0004DCD3A /* RNFirebaseInstanceId.m in Sources */, 839D916E1EF3E20B0077C7C8 /* RNFirebaseAdMobRewardedVideo.m in Sources */, + 168785AD210B584E00E4BD57 /* RCTConvert+UIBackgroundFetchResult.m in Sources */, 839D916C1EF3E20B0077C7C8 /* RNFirebaseAdMob.m in Sources */, 17AF4F6B1F59CDBF00C02336 /* RNFirebaseLinks.m in Sources */, 8376F7161F7C149100D45A85 /* RNFirebaseFirestoreCollectionReference.m in Sources */, diff --git a/ios/RNFirebase/converters/RCTConvert+UIBackgroundFetchResult.h b/ios/RNFirebase/converters/RCTConvert+UIBackgroundFetchResult.h new file mode 100644 index 00000000..e0ed190a --- /dev/null +++ b/ios/RNFirebase/converters/RCTConvert+UIBackgroundFetchResult.h @@ -0,0 +1,5 @@ +#import + +@interface RCTConvert (UIBackgroundFetchResult) + +@end diff --git a/ios/RNFirebase/converters/RCTConvert+UIBackgroundFetchResult.m b/ios/RNFirebase/converters/RCTConvert+UIBackgroundFetchResult.m new file mode 100644 index 00000000..28d78ba2 --- /dev/null +++ b/ios/RNFirebase/converters/RCTConvert+UIBackgroundFetchResult.m @@ -0,0 +1,9 @@ +#import "RCTConvert+UIBackgroundFetchResult.h" + +@implementation RCTConvert (UIBackgroundFetchResult) +RCT_ENUM_CONVERTER(UIBackgroundFetchResult, (@{ @"backgroundFetchResultNoData" : @(UIBackgroundFetchResultNoData), + @"backgroundFetchResultNewData" : @(UIBackgroundFetchResultNewData), + @"backgroundFetchResultFailed" : @(UIBackgroundFetchResultFailed)}), + UIBackgroundFetchResultNoData, integerValue) + +@end diff --git a/ios/RNFirebase/notifications/RNFirebaseNotifications.m b/ios/RNFirebase/notifications/RNFirebaseNotifications.m index decfac32..9de4e54f 100644 --- a/ios/RNFirebase/notifications/RNFirebaseNotifications.m +++ b/ios/RNFirebase/notifications/RNFirebaseNotifications.m @@ -113,16 +113,7 @@ RCT_EXPORT_METHOD(stopHandlingNotificationDisplayed) { completionHandlers = nil; } -RCT_EXPORT_METHOD(complete:(NSString*)handlerKey fetchResult:(NSString *)rnFetchResult) { - UIBackgroundFetchResult fetchResult = UIBackgroundFetchResultNoData; - if ([@"noData" isEqualToString:rnFetchResult]) { - fetchResult = UIBackgroundFetchResultNoData; - } else if ([@"newData" isEqualToString:rnFetchResult]) { - fetchResult = UIBackgroundFetchResultNewData; - } else if ([@"failed" isEqualToString:rnFetchResult]) { - fetchResult = UIBackgroundFetchResultFailed; - } - +RCT_EXPORT_METHOD(complete:(NSString*)handlerKey fetchResult:(UIBackgroundFetchResult)fetchResult) { void (^completionHandler)(UIBackgroundFetchResult) = completionHandlers[handlerKey]; completionHandlers[handlerKey] = nil; @@ -787,6 +778,12 @@ RCT_EXPORT_METHOD(jsInitialised:(RCTPromiseResolveBlock)resolve rejecter:(RCTPro return @[NOTIFICATIONS_NOTIFICATION_DISPLAYED, NOTIFICATIONS_NOTIFICATION_OPENED, NOTIFICATIONS_NOTIFICATION_RECEIVED]; } +- (NSDictionary *) constantsToExport { + return @{ @"backgroundFetchResultNoData" : @(UIBackgroundFetchResultNoData), + @"backgroundFetchResultNewData" : @(UIBackgroundFetchResultNewData), + @"backgroundFetchResultFailed" : @(UIBackgroundFetchResultFailed)}; +} + + (BOOL)requiresMainQueueSetup { return YES; diff --git a/lib/modules/notifications/index.js b/lib/modules/notifications/index.js index 5cc52591..9a3a739f 100644 --- a/lib/modules/notifications/index.js +++ b/lib/modules/notifications/index.js @@ -45,6 +45,12 @@ type OnNotificationOpenedObserver = { next: NotificationOpen, }; +type BackgroundFetchResult = { + noData: string, + newData: string, + failure: string, +}; + const NATIVE_EVENTS = [ 'notifications_notification_displayed', 'notifications_notification_opened', @@ -78,6 +84,7 @@ const hasListeners = (eventType: string): boolean => { */ export default class Notifications extends ModuleBase { _android: AndroidNotifications; + _backgroundFetchResult: BackgroundFetchResult; constructor(app: App) { super(app, { @@ -89,6 +96,13 @@ export default class Notifications extends ModuleBase { }); this._android = new AndroidNotifications(this); + const nativeModule = getNativeModule(this); + this._backgroundFetchResult = { + noData: nativeModule.backgroundFetchResultNoData, + newData: nativeModule.backgroundFetchResultNewData, + failure: nativeModule.backgroundFetchResultFailure, + }; + SharedEventEmitter.addListener( // sub to internal native event - this fans out to // public event name: onNotificationDisplayed @@ -153,6 +167,10 @@ export default class Notifications extends ModuleBase { return this._android; } + get backgroundFetchResult(): BackgroundFetchResult { + return { ...this._backgroundFetchResult }; + } + /** * Cancel all notifications */