Completion Handler issue fileprovider

I am having a bug while calling completionHandler after file is being downloaded in fileprovider extension. sometimes app refreshes the gui completely and sometime it does not. When user clicks the item download button - (void)startProvidingItemAtURL:(NSURL *)url completionHandler:(void (^)(NSError *))completionHandler is called and file starts to download. at that time i store the completion handler in a variable in order to call it when download is finished. and when download is finished in -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location i call the completion handler and then file opens but sometime in the background gui is being refreshed completely and sometime it stays where it is.