Warning: Application delegate received a call to -app: execute FetchWithCompletionHandler: but no completion handler was called
I am implementing performFetchWithCompletionHandler
(i.e. background fetch) to load some data from the server.
To do this, internally performFetchWithCompletionHandler
, so as not to block the main thread, I create and start a new task (so in the background thread) , and when the task is completed, I call CompletionHandler
withperformFetchWithCompletionHandler
But never mind, as soon as it is called performFetchWithCompletionHandler
, I get immediately in the log (and before the download task completes)
Warning. The application delegate received a call to -application: execute FetchWithCompletionHandler: but the completion handler was never called.
so i can't figure out how to do it? does this mean that the entire job should be done inside a procedure performFetchWithCompletionHandler
(therefore in the main thread) and performFetchWithCompletionHandler
should only return after the entire job has finished, thus blocking the main thread?
please help me understand how to do it right.
This is my code (it's in delphi, but it does exactly what I describe earlier, without a network connection, which I replace in sleep (15000)):
class procedure TMainForm.performFetchWithCompletionHandler(self: id; _cmd: SEL; application: PUIApplication; completionHandler: id);
begin
aTaskID := SharedApplication.beginBackgroundTaskWithExpirationHandler(SynchLocationsTaskExpired);
//load the Profiles in other thread to not block the calling thread
fSynchLocationsTask := TThread.CreateAnonymousThread(
procedure
begin
Sleep(15000);
TThread.Queue(nil,
procedure
begin
ExecutePerformFetchCompletionHandler(completionHandler, UIBackgroundFetchResultNewData); // ==> here the app crash like completionHandler is not valid anymore
SharedApplication.endBackgroundTask(aTaskID);
end);
end);
fSynchLocationsTask.FreeOnTerminate := False;
fSynchLocationsTask.Start;
// => here i receive in log Warning: Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called
end;
source to share
No one has answered this question yet
See similar questions:
or similar: