PushKit PKPushRegistryDelegate does not get callbacks - ios

After upgrading my app to Xcode8/Swift 3, I no longer receive callbacks from the PKPushRegistryDelegate.
I have verified all steps in Apple´s Voice Over IP (VoIP) Best Practices.
My device logs the following that might be related:
callservicesd[92] : [WARN] Ignoring voipRegister request because either no bundleIdentifier could be determined (0) or no environment could be determined (1)
My AppDelegate:
var voipRegistry: PKPushRegistry!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = Set([.voIP])
}
extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
print("didInvalidatePushTokenForType")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
print("Incoming voip notfication: \(payload.dictionaryPayload)")
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, forType type: PKPushType) {
print("voip token: \(credentials.token)")
}
}

I figured I had to enable "Push Notifications" under my target´s Capabilities:

Related

iOS 13 not getting VoIP Push token

I register delegate for PKPushRegistry in AppDelegate method func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool by following code:
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: nil)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [.voIP]
self.voipRegistry = voipRegistry
When I run app on iOS 12 everything works correctly - method func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) is triggered, but in iOS 13 case this method is not triggered at all.
What I do wrong in iOS 13 case? May be I need add some additional code?
I don't know what changed but after day everything is works - token is received, method func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) is triggered.

didReceiveIncomingPushWith - not working - iOS

I have implemented VOIP in swift.
Earlier it was working fine.
But, Now it is not triggering the didReceiveIncomingPushWith function.
Please find my configuration
let config = CXProviderConfiguration.init(localizedName: "AppName")
var provider: CXProvider!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
provider = CXProvider(configuration: config)
provider.setDelegate(self, queue: DispatchQueue.main)
self.registerVOIP()
}
func registerVOIP() {
//register for voip notifications
pushRegistry = PKPushRegistry(queue: DispatchQueue.main)
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = Set([PKPushType.voIP])
}
extension AppDelegate : PKPushRegistryDelegate{
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
}
}
In the extension method, didUpdate works fine, since delegate is set in didiFinishLoad
I am using QuickBlox for VOIP
I check the voip certificate everything is fine.
Here the quick box new session delegate
extension AppDelegate : QBRTCClientDelegate{
func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
print(#function)
}
}
the didReceiveNewSession function is trigger when receives a new call (If the app is in foreground)
Your code is fine, it is Quickblox server-side code needs to be changed.

Unable to install voip app in iPhone 6

I am getting below error on running my app on iPhone 6. I am trying to implement VoIP feature.
What is the solution for this ? Any help will be appreciated. Thanks.
I am using below code for VoIP feature.
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) {
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.desiredPushTypes = [PKPushType.voIP]
voipRegistry.delegate = self;
}
extension AppDelegate : PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
NSLog("PusRegistry didUpdateCredential....")
let deviceTokenString: String = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
NSLog("PushCredentials: \(deviceTokenString)" )
UIPasteboard.general.string = deviceTokenString
showLocalNotifiacation(text: "Received pushCredential")
NSLog("Token is : \(deviceTokenString)")
}
func pushRegistry(_ registry: PKPushRegistry,
didInvalidatePushTokenFor type: PKPushType) {
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
NSLog("<><><><><><><><><><><><><><><><><>><><><><><><><>><><>><><><><><")
NSLog("<><><><><><><><><><><><><><><><><>><><><><><><><>><><>><><><><><")
NSLog("<><><><><><><><><><><><><><><><><>><><><><><><><>><><>><><><><><")
NSLog("<><><><><><><><><><><><><><><><><>><><><><><><><>><><>><><><><><")
NSLog("<><><><><><><><><><><><><><><><><>><><><><><><><>><><>><><><><><")
NSLog("<><><><><><><><><><><><><><><><><>><><><><><><><>><><>><><><><><")
NSLog("<**************** Syncing data because of VOIP ***************")
sharedSilentPushSyncManager.syncDataForOperation("Syncing... for voip")
showLocalNotifiacation(text: "Received voip push")
}
}
Try this one!
1.Open your Xcode.
2.Go to your project target.
3.Click Capabilities tab in target.
4.Check with the following screenshot and enable Push Notification, Background Modes capabilities.
5.check your info.plist of your project.
6.Check your settings provided with above information and correct it.
Thank you!

Server getting error when trying to send PKPush

I am using the following code on the iOS side to get PKPush notifications working correctly. didUpdate is getting called and the server is sending a push to the correct token but the server is getting this error:
An error response packet was received from the APNS server: APNS: [1] Invalid token.
func voipRegistration() {
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushType.voIP]
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
//
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
//
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
NSLog("Device token \(deviceTokenString)")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: #escaping () -> Void) {
//
}
I have the following background modes set:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>voip</string>
<string>fetch</string>
<string>remote-notification</string>
</array>
And I am pointing to my development certificate while the server is pointing to the sandbox. What am I doing wrong?

iOS PushKit registration not working on iOS10

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:
But none of the delegate is getting called when I launch the app.
It also not working on iOS 9.
I solved it just simply by enabling Push Notifications in capabilities as:
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

Resources