I am making an attempt to implement background duties in iOS utilizing the react-native-background-fetch bundle. After I manually set off a background fetch from Xcode (Debug > Simulate Background Fetch), the occasion works appropriately. Nevertheless:
On an actual machine, the background fetch occasion doesn’t set off robotically after quarter-hour.
Within the iOS simulator, the occasion doesn’t set off robotically—I’ve to manually set off it from Xcode.
Moreover, I obtain the next message:
“The operation couldn’t be accomplished. Background procssing activity was not registered in AppDelegate didFinishLaunchingWithOptions. See iOS Setup Information.”
my AppDelegate.mm
#import "AppDelegate.h"
#import
#import
#import
#import
#import
enter code right here
#if RCT_NEW_ARCH_ENABLED
#import
#import
#import
#import
#import
#import
#import
static NSString *const kRNConcurrentRoot = @"concurrentRoot";
@interface AppDelegate () {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr _reactNativeConfig;
fb::react::ContextContainer::Shared _contextContainer;
}
@finish
#endif
@implementation AppDelegate
- (BOOL)software:(UIApplication *)software didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTAppSetupPrepareApp(software);
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
[[TSBackgroundFetch sharedInstance] didFinishLaunching];
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
#if RCT_NEW_ARCH_ENABLED
_contextContainer = std::make_shared<:react::contextcontainer const="">();
_reactNativeConfig = std::make_shared<:react::emptyreactnativeconfig const="">();
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
#endif
NSDictionary *initProps = [self prepareInitialProps];
UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"P625", initProps);
if (@out there(iOS 13.0, *)) {
rootView.backgroundColor = [UIColor systemBackgroundColor];
} else {
rootView.backgroundColor = [UIColor whiteColor];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
/// This methodology controls whether or not the `concurrentRoot`function of React18 is turned on or off.
///
/// @see: https://reactjs.org/weblog/2022/03/29/react-v18.html
/// @word: This requires to be rendering on Cloth (i.e. on the New Structure).
/// @return: `true` if the `concurrentRoot` feture is enabled. In any other case, it returns `false`.
- (BOOL)concurrentRootEnabled
{
// Swap this bool to activate and off the concurrent root
return true;
}
- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = [NSMutableDictionary new];
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
#endif
return initProps;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"principal" withExtension:@"jsbundle"];
#endif
}
#if RCT_NEW_ARCH_ENABLED
#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr<:react::jsexecutorfactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
delegate:self
jsInvoker:bridge.jsCallInvoker];
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
}
#pragma mark RCTTurboModuleManagerDelegate
- (Class)getModuleClassFromName:(const char *)identify
{
return RCTCoreModulesClassProvider(identify);
}
- (std::shared_ptr<:react::turbomodule>)getTurboModule:(const std::string &)identify
jsInvoker:(std::shared_ptr<:react::callinvoker>)jsInvoker
{
return nullptr;
}
- (std::shared_ptr<:react::turbomodule>)getTurboModule:(const std::string &)identify
initParams:
(const fb::react::ObjCTurboModule::InitParams &)params
{
return nullptr;
}
- (id)getModuleInstanceFromClass:(Class)moduleClass
{
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
#endif
@finish
What I Have Tried:
- Manually triggering the occasion from Xcode → Works (Debug > Simulate Background Fetch).
- Working on an actual machine → Background fetch doesn’t set off robotically after quarter-hour.
- Working in an iOS simulator → Background fetch doesn’t set off robotically; requires handbook triggering.
- Checked Background Modes in Xcode – Enabled Background fetch and Background processing.
- Ensured TSBackgroundFetch is initialized – Added [[TSBackgroundFetch sharedInstance] didFinishLaunching] in AppDelegate.mm.
- Set background fetch interval – Used UIApplicationBackgroundFetchIntervalMinimum
Atmosphere:
React Native model: 0.69.4
react-native-background-fetch model: 4.2.5
iOS model: 18.3.2
Xcode model: 16.2
How can I be certain that background fetch is appropriately registered and robotically triggered each on an actual iOS machine and within the simulator? Any insights on resolving this error?