Background fetch not trigger at Release mode TestFlights, but it's working on Debug mode on devices.
I'm working on background fetch for local notification function with time intervals 15 min. I'm getting log's each 15min time intervals on the debug mode devices. But still not able success with the release mode and TestFlights.
Environment
Versions,
"react-native": "0.70.0",
"react-native-background-fetch": "^4.2.5",
Platform: iOS Device manufacturer / model: iPhone 15
Here I have added my latest log screen shot
AppDelegate.m
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
#import "Orientation.h"
#import <TSBackgroundFetch/TSBackgroundFetch.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
return [RCTLinkingManager application:app openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"XXXXX"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// [REQUIRED] Register BackgroundFetch
[[TSBackgroundFetch sharedInstance] didFinishLaunching];
return YES;
}
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
completionHandler(UIBackgroundFetchResultNewData);
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [Orientation getOrientation];
}
@end
info.plist
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.transistorsoft.fetch</string>
</array>
code
// Use Effect for data fetching and permissions
useEffect(() => {
initBackgroundFetch();
requestPermissions();
}, []);
const initBackgroundFetch = async () => {
// Step 1: Configure BackgroundFetch as usual.
let status = await BackgroundFetch.configure({
minimumFetchInterval: 15,
forceAlarmManager: true
}, async (taskId) => {
// This is the fetch-event callback.
console.log("fetch-event callback: ", taskId);
fetchNotification(dispatch, previousDataRef);
switch (taskId) {
case 'react-native-background-fetch':
console.log("switch taskId: ", taskId);
break;
default:
console.log("default taskId log: ");
}
BackgroundFetch.finish(taskId);
}, async (taskId) => {
BackgroundFetch.finish(taskId);
});
// Step 2: Schedule a custom "oneshot" task "com.transistorsoft.fetch" to execute 5000ms from now.
BackgroundFetch.scheduleTask({
taskId: "react-native-background-fetch",
forceAlarmManager: true,
delay: 5000
});
};
You need to be patient. It can take a couple of days before Apple’s machine-learning algorithm kicks in. Just periodically open the app to foreground like a normal user would do.
Hi, i am encountering the exact same issue. configuring and scheduling background fetch with react-native-background-fetch
for some reason the tasks running fine if i am running them in the foreground, when going to background, nothing happens. no background tasks that runs from foreground OR from the schedule tasks are being invoked.
at first it runs via plugged real device (xcode) but never runs on a test flight version.
i will be happy to get some help :) very frustrating.
@christocracy Thanks for the reply. However, I'm still unable to fetch data at 15-minute intervals in the background on the TestFlight version. But It works when testing in debug mode via cable plugged devices.
The plug-in has no control over when the OS decides to fire events. If it works in simulated tasks, your job is done.