iOS 10:如何在应用程序处于后台时显示传入的VOIP呼叫通知?

我正在进行audio/video call ,试图让来电notification循环播放1分钟,就像iOS WhatsApp显示应用程序是后台时, Notification banner隐藏并显示铃声1分钟。

我试过这段代码,它只触发一次:

  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"); } }]; 

我怎样才能做到这一点? 我正在使用UserNotifications.framework (iOS 10)PushKit

我建议的是,本地通知仅在特定时间可见。 您需要做的是在通话时设置本地通知或通知。 触发通知时,在通知的委托方法中,您必须在NSTimer的帮助下构建自定义逻辑。

创建类似于要为呼叫显示的推送通知/或视图的视图。 将其添加到“应用程序窗口”,使其显示在所有视图的顶部。 3秒后删除此视图,在逻辑中您可以显示相同的视图1分钟。

iOS 10 CallKit更好,没有更多通知,但系统调用UI,就像本机调用一样。 Github上有一些示例代码,比Apple的Speakerbox样本更容易阅读。