2017-06-01 52 views
2

在后台模式下处理我的VoIP应用程序我使用的代码如下,它使我的voip App在后台进入时保持清醒状态,或者在后台进入后台时锁定电话,到达时,它会显示通知。我看到在IOS 8和更高版本setKeepAliveTimeout不再工作,我们需要使用Pushkit,有没有编码我们的服务器端使用pushKit?如何在后台应用程序中使用Pushkit与背景

- (void)registerKeepAliveHandler:(UIApplication*) application 
{ 
    LogInfo(TAG_MAIN, @"Registering KeepAliveTimeout"); 
    [application setKeepAliveTimeout:600 handler:^{ 
     [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_KEEPALIVE_RECEIVED object:nil]; 
     NSMutableString* statusStr = [[NSMutableString alloc] init]; 
     switch ([[UIApplication sharedApplication] applicationState]) { 
      case UIApplicationStateActive: 
       [statusStr appendString:@"foreground"]; 
       break; 
      case UIApplicationStateInactive: 
       [statusStr appendString:@"inactive"]; 
       break; 
      case UIApplicationStateBackground: 
       [statusStr appendString:@"background"]; 
       break; 
      default: 
       assert(0); 
       break; 
     } 
     LogInfo(TAG_MAIN, @"===================================== Keepalive received in %@ application status ===============================", statusStr); 
     [UIApplication getIPAddress]; 
     LogInfo(TAG_MAIN, @"%@", [[UIDevice currentDevice] batteryInfo]); 
     [[SipEngine sharedInstance] isServerReachable]; 
     [[SipEngine sharedInstance] isRegistered]; 
     [[SipEngine sharedInstance] startStopRegistration]; 
     [[[SipEngine sharedInstance] registration] registering]; 
    }]; 

} 

回答

0

如果你想让你的应用程序处于死亡状态以及知道来电并进一步处理,那么你应该使用推送工具包安静通知。 (这种方式的WhatsApp通话,Skype公司等应用的工作原理)

Refer

#import "AppDelegate.h" 

@interface AppDelegate() 

@end 

@implementation AppDelegate 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 


    pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()]; 
    pushRegistry.delegate = self; 
    pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; 

    return YES; 
} 

#define PushKit Delegate Methods 

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{ 
    if([credentials.token length] == 0) { 
     NSLog(@"voip token NULL"); 
     return; 
    } 

    NSLog(@"PushCredentials: %@", credentials.token); 
} 

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type 
{ 
    NSLog(@"didReceiveIncomingPushWithPayload"); 
} 


@end 

Way to schedule local notification based on puskit payload

+0

嗨@哈斯,谢谢。如果我想使用上面的函数,而不是NSLog(@“didReceiveIncomingPushWithPayload”);你有什么想法我需要使用?因为以这种方式它不起作用。 – Steven

+0

欢迎@Steven,如果我的回答对你有帮助,那么你可以赞成并接受它。让我知道我是否可以随时帮助你。 – Hasya

+0

你能接收Pushkit有效载荷吗?如果是的话,那么在pushkit有效载荷的基础上,您可以安排本地通知与来电的声音,也可以添加交互式事件来接受或拒绝call.https://github.com/hasyapanchasara/PushKit_SilentPushNotification/issues/1 – Hasya

0

走在前面,它的强制使用Pushkit为背景(BG)的VoIP应用程序在iOS的,因为它是要贬低网络电话BG插座完全与iOS 11.(我认为已经他们已经弃用iOS版10 SDK支持,但iOS 10与SDK 9配合使用)

要回答你的问题,不需要在服务器端实现APNS接口与Apple的APNS云进行通话,以便您的应用可以通过Apple接收VOIP呼叫等VoIP通话。此外,请注意BG中的VOIP应用程序如果处于封闭网络(无互联网),则无法在iOS上工作,因为APNS接口必须将Voip Picking传送到正在使用Pushkit的应用程序。

+0

@Ayush您好,我无法找到任何教程如何实现APNS接口服务器端与苹果的APNS云谈话。无论如何,找到一些教程如何做到这一点? – Steven

+0

这有点奇怪。苹果实际上已经提供了完整的文档。 https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW1 – Ayush

相关问题