如何在Voip App中使用带有背景的pushkit

时间:2017-06-01 08:15:24

标签: objective-c apple-push-notifications pushkit

我在后台模式下使用我的Voip应用程序,我使用下面的代码,它可以让我的voip App在后台进入时保持清醒状态,或者当它进入后台并在通话到达时锁定手机,它会显示通知。我看到在IOS 8及更高版本 setKeepAliveTimeout 不再工作了,我们需要使用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];
    }];

}

2 个答案:

答案 0 :(得分:1)

如果您想要处于被杀死状态的应用程序以及了解来电并进行进一步处理,那么您应该使用Push kit无声通知。 (这种方式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

答案 1 :(得分:0)

继续,它必须在iOS中使用Pushkit for Background(BG)Voip应用程序,因为它将完全弃用iOS 11的Voip BG套接字。(我认为他们已经弃用了iOS 10 SDK中的支持,但iOS 10适用于SDK 9)

要回答您的问题,不,您需要在服务器端实施APNS界面,以便与Apple的APNS云通信,以便您的应用可以通过Apple接收VOIP推送Voip呼叫等。此外,请注意BG中的VOIP应用程序如果处于封闭网络(无互联网),则不再适用于iOS,因为必须使用APNS接口将Voip Push传送到使用Pushkit的应用程序。