Search code examples
iosvoippushkit

pushRegistry:didUpdate:pushCredentials not being called


Looked at past questions about this but the answers to those have already been applied to my project but the pushRegistry() delegate method isn't getting invoked.

First here's the code:

import UIKit
import PushKit
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate{

    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        let notificationSettings  = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)
        application.registerUserNotificationSettings(notificationSettings)

        UNUserNotificationCenter.current().delegate = self
        UIApplication.shared.registerForRemoteNotifications()

        let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
        voipRegistry.desiredPushTypes = Set([PKPushType.voIP])
        voipRegistry.delegate = self;

        return true
    }
...
}

extension AppDelegate: PKPushRegistryDelegate {
    func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        NSLog("voip token: \(pushCredentials.token)")
    }

The following app capabilities have been enabled: - Push Notifications - Background Modes - Background Fetch - Remote Notifications

I'm using Xcode 9.1 Beta which no longer has Voip as an explicit capability, apparently this is no longer needed and importing PushKit should suffice.

On the provisioning portal Push Notifications have been enabled for the app id. (A Void Push cert has been generated but obviously can't use this to send the pushes yet)


Solution

  • apparently this is no longer needed and importing PushKit should suffice.

    I read a couple of posts saying this but its not correct. In order to get things working I had to manually edit the info.plist to add voip to the list of background modes.

     <string>voip</string>
    

    What are Apple playing at? Why have they removed this as a capability from Xcode if its still required?