Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS VoIP push notifications (PushKit)

I'm searching informations about push notifications for VoIP push notifications. Some point remains unclear to me :

1) If the user has not the application opened, and then he receives a call. Is there a mean to launch the applications from the notification ?

2) How does the application wait for a specific event ? How does my device would know he receive a call from someone for example ?

3) I use the Appdelegate file from https://github.com/Hitman666/ios-voip-push but in my case it doesn't work (many errors), here is a preview of the error i get.

Thanks

like image 581
babaaba78 Avatar asked Apr 26 '17 15:04

babaaba78


1 Answers

1) If the user has not opened the application, and then he receives a call. Is there a mean to launch the applications from the notification ?

- First time user has to tap on app icon and open it then only device id will get register to receive push kit payload. then no need to open app. It will also work when app is in killed state and you have to schedule local notification as per push kit payload.

2) How does the application wait for a specific event ? How does my device would know he receive a call from someone for example ?

- You have to schedule local notification as per push kit payload.

3) I use the Appdelegate file from https://github.com/Hitman666/ios-voip-push but in my case it doesn't work (many errors), here is a preview of the error i get.

- Refer below code

import UIKit
import PushKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


        let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
        application.registerForRemoteNotificationTypes(types)

        self.PushKitRegistration()

        return true
    }

    //MARK: - PushKitRegistration

    func PushKitRegistration()
    {

        let mainQueue = dispatch_get_main_queue()
        // Create a push registry object
        if #available(iOS 8.0, *) {

            let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)

            // Set the registry's delegate to self

            voipRegistry.delegate = self

            // Set the push type to VoIP

            voipRegistry.desiredPushTypes = [PKPushTypeVoIP]

        } else {
            // Fallback on earlier versions
        }


    }


    @available(iOS 8.0, *)
    func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
        // Register VoIP push token (a property of PKPushCredentials) with server

        let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes),
            count: credentials.token.length).map { String(format: "%02x", $0) }.joinWithSeparator("")

        print(hexString)


    }


    @available(iOS 8.0, *)
    func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
        // Process the received push


    }

}

Get some more information about how to integrate pushkit for VOIP based app.

Just updated with Swift 4.0 code as well.

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

like image 83
Hasya Avatar answered Sep 30 '22 17:09

Hasya