2017-01-25 30 views
5

我正在处理audio/video call并尝试拨打电话notification循环1分钟如whatsapp在iOS中显示应用程序为背景时,Notification banner用铃声隐藏并显示1分钟。iOS 10:如何在应用程序处于后台时显示传入VOIP呼叫通知?

我已经尝试了这个代码我只触发单时间:

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

谢谢!

+0

@Jayprakash Dubey:你能帮助解决这个问题吗? –

+0

您想要在此处发出连续1分钟或间隔1分钟的通知吗? – gurmandeep

+0

我想通知显示3秒和隐藏,这个过程应该只运行1分钟,就像应用程序在ios中的背景时whatsapp来电 –

回答

3

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

创建一个视图,类似于您希望显示的呼叫的推送通知/或视图。将它添加到应用程序窗口,以便它显示在所有视图之上。 3秒后,移除该视图,并在逻辑中显示1分钟的相同视图。

让我知道这是否有帮助。

+1

是的,它做了我的30%这个问题thanxx很多 –

+0

好的回答.... – Hasya

+0

随着backgroundExecution随着到期处理程序的帮助已经完成了95%我完全需要,因为我只能做30secs :) –

3

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

+0

请帮我解决这个问题:http:// stackoverflow.com/questions/42266258/ios-9-beginbackgroundtaskwithexpirationhandler-is-getting-called-before-timout/42274565?noredirect=1#comment71732371_42274565 –

+0

请检查我的建议是否适合您。 – Qiulang

+0

我的意思是我回答另一个问题。不是这个:) – Qiulang

相关问题