Our application uses didReceiveRemoteNotification: fetchCompletionHandler: UIApplicationDelegate to start loading when a push content-available notification is received.
Individual steps that the application takes:
[1] Get notified
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { NSLog(@"Remote download push notification received"); [AFHTTPSessionManager_Instance downloadFile:completionHandler]; }
[2] Launch a new download task
- (void)downloadFile:(void (^)(UIBackgroundFetchResult))completionHandler { NSURLSessionDownloadTask *task = [AFHTTPSessionManager_Instance downloadTaskWithRequest:request progress:nil destination:nil completionHandler:nil]; [task resume]; NSLog(@"Starting download of %@", request.URL.absoluteString);
[3] Refer to the download
[self setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) { NSLog(@"Download complete!");
The result is a log like this:
2015-09-21 15:38:57.145 App[315:20933] Remote download push notification received 2015-09-21 15:38:57.485 App[315:20933] Starting download of http:
But sometimes (completely random) I see logs like this:
2015-09-21 15:38:57.145 App[315:20933] Remote download push notification received 2015-09-21 15:38:57.485 App[315:20933] Starting download of http:
In other words, the download never completes, it seems the application is freezing its background session. Because when I bring the application back to the forefront, the download will be completed at some point.
Has anyone seen this behavior before?
FYI: I enabled the correct features, used the correct profile profile, and the application has permissions to run in the background.
Update: We used answers / comments in AFNetworking 2.0 and background transfers when developing the background manager
ios objective-c push-notification afnetworking
basvk Sep 21 '15 at 2:04 2015-09-21 14:04
source share