RNBackgroundFetch failed to start, status:1 in iOS
Your Environment
- Plugin version:4.16.5
- Platform: iOS
- Device manufacturer / model: iPhone 11
- React Native version (
react-native -v):0.74.2
iOS not working get error RNBackgroundFetch failed to start, status: 1
I ran into a similar issue. I was using RN 0.71 and everything was working fine. When I upgraded to 0.74, I wasn't able to get my RNBackgroundFetch to start. I think this must be due to Yoga 3.0 or Bridgeless by default under the New Architecture brought by RN 0.74. Unfortunately, the only way I was able to resolve this (today) was by downgrading back to 0.71. @SKHRAPP
Plugin version:4.16.5
No such version. See CHANGELOG:
https://github.com/transistorsoft/react-native-background-fetch/blob/master/CHANGELOG.md
@christocracy do we see a version in the foreseeable near future to support RN 0.74?
It can be made to work with any version. This is the first I’ve heard of a problem. I’m on vacation, currently.
I just generated a fresh new hello-world app with [email protected], followed the Setup Instructions
{
"name": "foo2",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"react": "18.2.0",
"react-native": "0.74.3",
"react-native-background-fetch": "^4.2.5"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.74.85",
"@react-native/eslint-config": "0.74.85",
"@react-native/metro-config": "0.74.85",
"@react-native/typescript-config": "0.74.85",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
"engines": {
"node": ">=18"
},
"packageManager": "[email protected]"
}
Add the following to my App.tsx:
React.useEffect(() => {
initBackgroundFetch();
}, []);
const initBackgroundFetch = async () => {
const status:number = await BackgroundFetch.configure({
minimumFetchInterval: 15 // <-- minutes (15 is minimum allowed)
}, async (taskId:string) => {
console.log('******************* [BackgroundFetch] taskId', taskId);
// Finish.
BackgroundFetch.finish(taskId);
}, (taskId:string) => {
// Oh No! Our task took too long to complete and the OS has signalled
// that this task must be finished immediately.
console.log('******************* [BackgroundFetch] TIMEOUT taskId:', taskId);
BackgroundFetch.finish(taskId);
});
}
I simulate a couple of com.transistorsoft.fetch events and voila:
RNBackgroundFetch failed to start, status:1
Btw, status: 1 means BackgroundFetch.STATUS_DENIED. As in, the user disabled "Background App Refresh" in your app settings.
Aside for these changes, along with obviously changes to my podfile.lock, suddenly my background refresh stopped working. I have double checked that I have this permission enabled in my iPhone settings. The error I see locally in xcode is:
"[TSBackgroundFetch scheduleTask] ERROR: Failed to submit task request: Error Domain=TSBackgroundFetch Code=0 "Background procssing task was not registered in AppDelegate didFinishLaunchingWithOptions. See iOS Setup Guide." UserInfo={NSLocalizedFailureReason=Background procssing task was not registered in AppDelegate didFinishLaunchingWithOptions. See iOS Setup Guide.}"
below is my full AppDelegate.mm as well as my info.plist:
`#import "AppDelegate.h" #import <MSAL/MSAL.h> #import <React/RCTBundleURLProvider.h> #import "Orientation.h" #import <TSBackgroundFetch/TSBackgroundFetch.h> #import <Firebase.h> #import "RNFBMessagingModule.h" #import <React/RCTLinkingManager.h>
@implementation AppDelegate
-
(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return [Orientation getOrientation]; }
-
(void)applicationDidBecomeActive:(UIApplication *)application { [UIApplication sharedApplication].applicationIconBadgeNumber = 0; }
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIRApp configure]; self.moduleName = @"magen"; self.initialProps = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions]; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. for (NSString *familyName in [UIFont familyNames]){ NSLog(@"Family name: %@", familyName); for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { NSLog(@"--Font name: %@", fontName); } } [[TSBackgroundFetch sharedInstance] didFinishLaunching];
return [super application:application didFinishLaunchingWithOptions:launchOptions]; }
-
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { return [RCTLinkingManager application:application openURL:url options:options]; }
-
(NSURL *)bundleURL { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif }
/// This method controls whether the concurrentRootfeature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: true if the concurrentRoot feature is enabled. Otherwise, it returns false.
-
(BOOL)concurrentRootEnabled { return true; }
-
(void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts { UIOpenURLContext *context = URLContexts.anyObject; NSURL *url = context.URL; NSString *sourceApplication = context.options.sourceApplication;
[MSALPublicClientApplication handleMSALResponse:url sourceApplication:sourceApplication]; }
@end `
`
TSBackgroundFetch Code=0
See above: https://github.com/transistorsoft/react-native-background-fetch/issues/514#issuecomment-2256062956
@christocracy I mentioned in my latest comment above that I have verified that this setting is enabled on my device.
This issue doesn't appear to be status one, so if you'd like, I can open a new issue. However, this is a critical issue my team and I are facing now so I'd love to get this resolved as soon as possible
@christocracy any chance you can update the example repo using latest RN 0.74 with your working solution?
This is not an RN issue, the error comes from the native iOS BGTaskScheduler API.
go ahead and generate yourself a fresh new hello-world app and try it.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.