Search code examples
iosasteriskpjsip

How to wake iOS apps when incoming calls comes using pjsip


I am working on pjsip audio call softphone application in iOS. I want my app to open when any call comes.

I have tried finding of AGI on asterisk. Register for pushtry now there is no document on pjsip what is next

// Register for VoIP notifications
- (void) voipRegistration {
    dispatch_queue_t mainQueue = dispatch_get_main_queue();
    // Create a push registry object
    PKPushRegistry * voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
    // Set the registry's delegate to self
    voipRegistry.delegate = self;
    // Set the push type to VoIP
    voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}

We have API working for silent notification using APNS. which wakes the app in normal flow. but when IVR considered i got smoke around my eyes.

This topic totally depends on asterisk implementation the scenario I am trying to understand is how can I implement the code for sending a push notification when a mediator tries to connect the call on dialed DTMF number on the IVR system in asterisk. can anyone help me, please?


Solution

  • You should store your voipRegistry as a property, otherwise it will be deallocated at the end of the method.

    Your delegate (object conforming to PKPushRegistryDelegate) will receive the token.

    You can implement this delegate method to get the token and send to the server:

    - (void)pushRegistry:(PKPushRegistry *)registry 
    didUpdatePushCredentials:(PKPushCredentials *)pushCredentials 
                 forType:(PKPushType)type {
        // get credentials.token
        // create registration using pjsip_regc_register()
    }
    

    On your server store the token. Use it with the APNS server API to activate your app when there is an inbound call.

    Then your app will launch and call the delegate method:

    - (void)pushRegistry:(PKPushRegistry *)registry 
    didReceiveIncomingPushWithPayload:(PKPushPayload *)payload 
                 forType:(PKPushType)type 
    withCompletionHandler:(void (^)(void))completion {
        // handle payload
    }