UIlocalNotification did now appear without starting background task

后端 未结 1 1079
夕颜
夕颜 2021-01-17 04:35

I have a voip application.

I am using UILocalNotification in my application to alert notification for incoming call when application in background.

相关标签:
1条回答
  • 2021-01-17 05:01

    Try This :

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
    
        __block UIBackgroundTaskIdentifier bgTask ;
        UIApplication  *app = [UIApplication sharedApplication];
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:bgTask];
            bgTask = UIBackgroundTaskInvalid;
        }];
        pollingTimer2 = [NSTimer scheduledTimerWithTimeInterval:4.0f target:self  selector:@selector(process)  userInfo:nil repeats:YES];
    }
    -(void) process
    {
       [self didLocalNotification];
    
    }
    
    -(void)didLocalNotification
    {
    
        [[UIApplication sharedApplication]cancelAllLocalNotifications];
        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
        if (localNotification == nil)
        {
            return;
        }
    
        NSLog(@"calling didLocalNotification");
        localNotification.applicationIconBadgeNumber =0;
        localNotification.alertBody =@"Message!";
        localNotification.soundName = UILocalNotificationDefaultSoundName;
        localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
        localNotification.timeZone = [NSTimeZone defaultTimeZone];
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    }
    
    0 讨论(0)
提交回复
热议问题