2

I am implementing PushKit for my VoIP application for iOS 10.

I have written this code in AppDelegate.swift file:

import PushKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {

var window: UIWindow?
private let _pushRegistry = PKPushRegistry(queue: DispatchQueue.main)

//MARK: - App Life Cycle -
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    //Register for local notifications
    NotificationController.registerNotifcationForApplication()
    
    //PushKit
    _pushRegistry.delegate = self
    var typeSet = Set<PKPushType>()
    typeSet.insert(.voIP)
    _pushRegistry.desiredPushTypes = typeSet
    
    window!.makeKeyAndVisible()
    return true
}

//MARK: - Delegates -
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials,  forType type: PKPushType) {
    DDLogVerbose("PushKit Token: \(credentials.token) length: \(credentials.token.count)")
    print("pushRegistry didUpdate credentials")
}

func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
    DDLogVerbose("")
    print("pushRegistry didInvalidatePushTokenForType")
}

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
    DDLogVerbose("Payload: \(payload.dictionaryPayload)")
    print("pushRegistry didReceiveIncomingPushWith")
}

}

I have enabled these background modes: enter image description here

But none of the delegate is getting called when I launch the app.
It also not working on iOS 9.

Community
  • 1
  • 1
D4ttatraya
  • 3,344
  • 1
  • 28
  • 50

1 Answers1

4

I solved it just simply by enabling Push Notifications in capabilities as:

enter image description here

Actually I tried this already also but it was not worked previously. Now I enabled it, closed Xcode 8.2.1, reopen, clean-build and it worked!

Thanks for this SO answer by vin25

Community
  • 1
  • 1
D4ttatraya
  • 3,344
  • 1
  • 28
  • 50