transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.47k stars 191 forks source link

RNBackgroundFetch failed to start, status:1 in iOS #514

Open SKHRAPP opened 1 month ago

SKHRAPP commented 1 month ago

Your Environment

iOS not working get error RNBackgroundFetch failed to start, status: 1

Barak-S commented 1 month ago

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

christocracy commented 1 month ago

Plugin version:4.16.5

No such version. See CHANGELOG:

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

Barak-S commented 1 month ago

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

christocracy commented 1 month ago

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 commented 1 month ago

I just generated a fresh new hello-world app with react-native@74.3, 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": "yarn@3.6.4"
}

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 commented 1 month ago

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

Barak-S commented 3 weeks ago
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

import "RNFBMessagingModule.h"

import <React/RCTLinkingManager.h>

@implementation AppDelegate

/// 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.

@end `

`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

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

`

christocracy commented 3 weeks ago

TSBackgroundFetch Code=0

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

Barak-S commented 3 weeks ago

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

Barak-S commented 3 weeks ago

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 commented 3 weeks ago

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

christocracy commented 3 weeks ago

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.