iOS 10:如何在应用程序处于后台时显示传入的VOIP呼叫通知? [英] iOS 10: How to show incoming VOIP call notification when app is in background?

查看:644
本文介绍了iOS 10:如何在应用程序处于后台时显示传入的VOIP呼叫通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理音频/视频通话并试图接听来电通知循环播放1分钟当应用程序为后台时,WhatsApp显示在 iOS 通知横幅隐藏并显示铃声1分钟。

I'm working on audio/video call and trying to get incoming call notification loop for 1 minute like WhatsApp shows in iOS when app is background, Notification banner hide and show with ringtone for 1 minute.

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

I have tried this code, it triggers only single 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");
        }
    }];

我如何实现这一目标?我正在使用 UserNotifications.framework(iOS 10) PushKit

How can I achieve this? I'm using UserNotifications.framework (iOS 10) and PushKit.

推荐答案

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

What I would suggest is that the local notification is only visible for that particular time. What you have to do is set a local notification or notification at the time of call. When the notification fires, in the delegate method of the notification you will have to build a custom logic with help of NSTimer.

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

Create a view similar to push notification/ or view which you want to show for the call. Add it to the Application Window so it is shown on top of all views. After 3 sec remove this view and in the logic you can show the same view for 1 min.

这篇关于iOS 10:如何在应用程序处于后台时显示传入的VOIP呼叫通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆