I using UILocalNotification for presenting notification when the background download completes, using the following code.`
- (void)presentNotificationForDownload:(NSString *)fileName withError:(BOOL)isError
{
UIApplication *application = [UIApplication sharedApplication];
UIApplicationState appCurrentState = [application applicationState];
if(appCurrentState == UIApplicationStateBackground)
{
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
if (isError) {
localNotification.alertBody = [NSString stringWithFormat:@"Downloading failed due some error"];
}
else
{
localNotification.alertBody = [NSString stringWithFormat:@"Downloading completed for file %@", fileName];
}
localNotification.alertTitle=@"Download complete";
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber =1;
[application presentLocalNotificationNow:localNotification];
}
}
`Everything works fine.But if I launch App after getting the local notification, some times its going to a non responding state.I am presenting the local notification inside following delegate method.
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{
if (error == nil)
{
NSLog(@"Task: %@ completed successfully", task);
dispatch_async(dispatch_get_main_queue(), ^{
[self presentNotificationForDownload:task.taskDescription withError:NO];
});
}
else
{
NSLog(@"Task: %@ completed with error: %@", task, [error localizedDescription]);
dispatch_async(dispatch_get_main_queue(), ^{
[self presentNotificationForDownload:task.taskDescription withError:YES];
});
}
}
I am not handling the notification now in Application delegate method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions