IOS 10: How to show an incoming VOIP call notification when an application is in the background?

I am working on an audio/video call and trying to get an incoming call notification cycle for 1 minute. LIKE whatsapp shows in iOS , when the application is the background, Hide and show the Notification banner with the ringtone for 1 minute.

I tried this code, I only run one time:

  UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.title = [NSString stringWithFormat:@"Video Call from %@",userId]; content.body = @""; content.userInfo = [userInfo mutableCopy]; content.sound = [UNNotificationSound soundNamed:@""]; NSDate *now = [NSDate date]; now = [now dateByAddingTimeInterval:3]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [calendar setTimeZone:[NSTimeZone localTimeZone]]; NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone fromDate:now]; UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:NO]; UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:@"INCOMING_VOIP_APN" content:content trigger:trigger]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { if (!error) { NSLog(@"PUSHKIT : INCOMING_VOIP_APN"); } }]; 

How can I achieve this, please help?

I use UserNotifications.framework (iOS 10) and PushKit .

Thanks!

+5
ios objective-c notifications usernotifications voip
source share
2 answers

I would suggest that local notification is only available for a specific time. You need to set a local notification or notification during a call. When the notification fires, in the notification delegate method, you will need to create custom logic using NSTimer .

Create a view that looks like a push notification / or view that you want to show for a call. Add it to the application window so that it appears on top of all views. After 3 seconds, delete this view, and in logic you can show the same view for 1 minute.

Let me know if this helps.

+3
source share

iOS 10 CallKit is much better, no more notifications, and a user interface with a system call, like a native call. Github has some sample code that is easier to read than the Apple Speakerbox sample.

+3
source share

All Articles