0

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
UIBittu
  • 215
  • 2
  • 13
  • if you launch the app as a result of your local notification, the "`-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification`" app delegate method will fire. I'm not sure what is happening between `didReceiveLocalNotification` and the `NSURLSession`. Perhaps you could elaborate on that in your question? – Michael Dautermann Nov 17 '15 at 07:00
  • @MichaelDautermann ,I have added the methods I am using for your reference..I think somehow the main queue is getting blocked .I don't know how – UIBittu Nov 17 '15 at 11:15

0 Answers0