// Copyright 2021-present 650 Industries. All rights reserved. #import #import #import @implementation EXBackgroundRemoteNotificationConsumer + (BOOL)supportsLaunchReason:(UMTaskLaunchReason)launchReason { return launchReason == UMTaskLaunchReasonRemoteNotification; } - (NSString *)taskType { return @"remote-notification"; } // Associating task to the consumer. - (void)didRegisterTask:(id)task { _task = task; } // Method that is being called when the JS app just finished launching, // after the native app was launched with the launch reason supported by the consumer. // For background notifications, `application:didReceiveRemoteNotification:fetchCompletionHandler:` is the entry point of this method, // so the task can be executed immediately here if the app is not foregrounded. - (void)didBecomeReadyToExecuteWithData:(NSDictionary *)data { if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) { [_task executeWithData:data withError:nil]; } } // Translate result received from JS to another (native) type that is then used for example as an argument in completion callbacks. - (NSUInteger)normalizeTaskResult:(id)result { if (!result || result == [NSNull null]) { return UIBackgroundFetchResultNoData; } switch ([result unsignedIntegerValue]) { case EXBackgroundNotificationResultNewData: return UIBackgroundFetchResultNewData; case EXBackgroundNotificationResultFailed: return UIBackgroundFetchResultFailed; case EXBackgroundNotificationResultNoData: default: return UIBackgroundFetchResultNoData; } } @end