Steven
Steven

Reputation: 782

how to use pushkit with background in Voip App

Curently for my Voip App in background mode I use the code bellow, that keeps my voip App awake when it goes in background or when It goes in background and lock the phone when the call arrive, it shows the notification. I saw that in IOS 8 and later setKeepAliveTimeout not work anymore and we need to use Pushkit, is there anyway to use pushKit without coding our server side?

- (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];
    }];

}

Upvotes: 3

Views: 4835

Answers (2)

Hasya
Hasya

Reputation: 9898

If you want to work your app in killed state as well to know incoming call and make further process then you should work with Push kit silent notification. ( this way Whatsapp call, Skype etc app works )

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

Upvotes: 1

Ayush
Ayush

Reputation: 400

Going ahead, its mandatory to use Pushkit for Background (BG) Voip apps in iOS as it's going to deprecate Voip BG sockets fully with iOS 11. (I think already they have deprecated the support in iOS 10 SDK, but iOS 10 works with SDK 9)

To answer your question, no, you need to implement APNS interface at your server side to talk to Apple's APNS cloud so that your app can receive VOIP Pushes for Voip Calls etc through Apple. Also, please note VOIP apps in BG will no more work for iOS if they are in closed network (no internet) as APNS interface is mandatory to deliver Voip Pushes to your app which is using Pushkit.

Upvotes: 0

Related Questions