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

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

问题描述

我正在处理 audio/video call 并尝试让来电 notification 循环 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天全站免登陆