Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background fetch never gets called

I know there are hundreds of topics out there concerning the background fetch on iOS. I simply cannot solve my problem to get the background fetch for my app to work. It is absoulutely substantial for the outcome of my app to have a working background fetch. My background fetch works fine on the simulator via Debug -> Simulate Background fetch and also on device with the special scheme setting: "Launch due to a background fetch event". I know that it doesn´t gets executed when the user is force quitting the app. I tried to lock the iPhone and wait for hours then unlock it to try to trigger the background fetch. Nothing happens. Actually everything works fine but the background fetch simply NEVER gets executed on my iPhone. I know that iOS has a special algorithm for calling background threads so a little patient is needed. But after 2 months of waiting for a background fetch to happen automatically I don´t have patients anymore. What I did:

  1. App capabilites: Background fetch activated
  2. Info.plist: Required background modes: App downloads content from the network
  3. App delegate:
 - (BOOL)application:(UIApplication *)application    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }

   [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:2.0];
    return YES;
}

- (void) application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    //Do my stuff
   completionHandler (UIBackgroundFetchResultNewData);
}
like image 630
tyler Avatar asked Oct 19 '22 15:10

tyler


1 Answers

Did you check out to go Settings->General->background app refresh and check if its enabled? It could be the problem...

like image 127
Javier Flores Font Avatar answered Dec 07 '22 00:12

Javier Flores Font