0

My app does the intended operations when I use Simulate Background Fetch in the Debug tab in Xcode, however, when the app is running on my phone nothing works.

Has this happened to someone before? How did you resolve it?

I'm currently using Swift 2.2 and Xcode 7.3

rmaddy
  • 314,917
  • 42
  • 532
  • 579
the_ccalderon
  • 2,006
  • 2
  • 13
  • 24

2 Answers2

1

Did you edit the schema in Run mode for the Launch due to a Background Fetch Event

iOS Background Fetch Not Working Even Though Correct Background Mode Configured

Community
  • 1
  • 1
g3ctong
  • 86
  • 4
  • Thanks for your help but when I do that the code gets executed, but only one time. When I run the app that it's installed on my iPhone, the code never gets executed. – the_ccalderon Sep 07 '16 at 15:30
0

iOS won't allow any app to run in the background unless the app ask for it and it will allow it to run for 10mins only to register for background execution:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    UIBackgroundTaskIdentifier identifier;
    identifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:identifier];
    }];
}
Karim H
  • 1,543
  • 10
  • 24
  • I do not understand your answer. I have enabled the necessary Background Modes and I also implemented the func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) method. What else do I need? – the_ccalderon Sep 08 '16 at 20:52
  • You need to tell iOS that you want background execution, settings modes is not necessary you have to explicitly requiring it. – Karim H Sep 09 '16 at 00:36