react-native-background-fetch icon indicating copy to clipboard operation
react-native-background-fetch copied to clipboard

RNBackgroundFetch failed to start, status:1 in iOS

Open SKHRAPP opened this issue 1 year ago • 13 comments

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

SKHRAPP avatar Jul 22 '24 11:07 SKHRAPP

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

Barak-S avatar Jul 22 '24 16:07 Barak-S

Plugin version:4.16.5

No such version. See CHANGELOG:

https://github.com/transistorsoft/react-native-background-fetch/blob/master/CHANGELOG.md

christocracy avatar Jul 22 '24 17:07 christocracy

@christocracy do we see a version in the foreseeable near future to support RN 0.74?

Barak-S avatar Jul 25 '24 12:07 Barak-S

It can be made to work with any version. This is the first I’ve heard of a problem. I’m on vacation, currently.

christocracy avatar Jul 25 '24 13:07 christocracy

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:

Screenshot 2024-07-29 at 10 02 02 AM

christocracy avatar Jul 29 '24 14:07 christocracy

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.

IMG_1968

christocracy avatar Jul 29 '24 14:07 christocracy

Screenshot 2024-08-13 at 9 40 01 AM Screenshot 2024-08-13 at 9 39 36 AM

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 `

`

BGTaskSchedulerPermittedIdentifiers com.foo.customtask com.transistorsoft.fetch CFBundleDevelopmentRegion en CFBundleDisplayName MAGIC CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString $(MARKETING_VERSION) CFBundleSignature ???? CFBundleURLTypes CFBundleTypeRole Editor CFBundleURLSchemes shareios CFBundleURLSchemes msauth.$(PRODUCT_BUNDLE_IDENTIFIER) CFBundleVersion $(CURRENT_PROJECT_VERSION) ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes msauthv2 msauthv3 LSRequiresIPhoneOS NSAppTransportSecurity NSExceptionDomains localhost NSExceptionAllowsInsecureHTTPLoads NSCameraUsageDescription This app requires access to the camera. NSFaceIDUsageDescription $(PRODUCT_NAME) Authentication with FaceID NSLocationWhenInUseUsageDescription NSMicrophoneUsageDescription This app does not require access to the microphone. NSPhotoLibraryUsageDescription App allows you to upload photos to the getstream chat interface UIAppFonts AntDesign.ttf Entypo.ttf EvilIcons.ttf Feather.ttf FontAwesome.ttf FontAwesome5_Brands.ttf FontAwesome5_Regular.ttf FontAwesome5_Solid.ttf Foundation.ttf Ionicons.ttf MaterialIcons.ttf MaterialCommunityIcons.ttf SimpleLineIcons.ttf Octicons.ttf Zocial.ttf Fontisto.ttf Lato-Black.ttf Lato-BlackItalic.ttf Lato-Bold.ttf Lato-BoldItalic.ttf Lato-Italic.ttf Lato-Light.ttf Lato-LightItalic.ttf Lato-Regular.ttf Lato-Thin.ttf Lato-ThinItalic.ttf Roboto-Black.ttf Roboto-BlackItalic.ttf Roboto-Bold.ttf Roboto-BoldItalic.ttf Roboto-Italic.ttf Roboto-Light.ttf Roboto-LightItalic.ttf Roboto-Medium.ttf Roboto-MediumItalic.ttf Roboto-Regular.ttf Roboto-Thin.ttf Roboto-ThinItalic.ttf UIBackgroundModes fetch processing remote-notification UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UISupportedInterfaceOrientations~ipad UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIViewControllerBasedStatusBarAppearance `

Barak-S avatar Aug 13 '24 13:08 Barak-S

TSBackgroundFetch Code=0

See above: https://github.com/transistorsoft/react-native-background-fetch/issues/514#issuecomment-2256062956

christocracy avatar Aug 13 '24 13:08 christocracy

@christocracy I mentioned in my latest comment above that I have verified that this setting is enabled on my device.

Barak-S avatar Aug 13 '24 14:08 Barak-S

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

Barak-S avatar Aug 13 '24 14:08 Barak-S

@christocracy any chance you can update the example repo using latest RN 0.74 with your working solution?

Barak-S avatar Aug 13 '24 14:08 Barak-S

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.

christocracy avatar Aug 13 '24 14:08 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 13 '24 01:09 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Sep 27 '24 02:09 github-actions[bot]