VOIP Notifications through One-Signal not working - ios

I have integrated VOIP notification using OneSignal in one of my iOS app. It was working fine in earlier days of my development but suddenly it stopped working. I have checked the code and found no changes. I also created a new sample project to check for the issue but no luck. I checked the onesignal delivery dashboard which showed that the notifications are received but the (didReceiveIncomingPushWith) method is never getting called. Please help me out with the issue.
Step 1: Remote Notification Permission
if #available(iOS 10, *) {
UNUserNotificationCenter.current().requestAuthorization(options:
[.badge, .alert, .sound]){ granted, error in }
} else {
application.registerUserNotificationSettings(
UIUserNotificationSettings(types: [.badge, .sound, .alert],
categories: nil))
}application.registerForRemoteNotifications()
Step 2: Pushkit Registration
let pushRegistry = PKPushRegistry(queue: DispatchQueue.main)
pushRegistry.desiredPushTypes = [.voIP]
pushRegistry.delegate = self
Step 3: Delegate Methods
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
print("VOIP : \(token)")
}
#available(iOS, introduced: 8.0, deprecated: 11.0)
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
//self.handlePushPayload(payload)
}
#available(iOS 11.0, *)
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: #escaping () -> Void) {
//self.handlePushPayload(payload)
completion()
}

Related

VoIP push does not deliver on a certain iOS device

We are developing a voip calling app. We are using CallKit and PushKit frameworks. A user recently reported that his iPhone is not receiving CallKit push anymore, but few days ago that was working. Please note mutable push is working on his device. We have collected device's console logs and learned that device did not receive voip push payload.
No firewalls installed and no recent change history of network settings.
Environments info:
Device Model: iPhone Xs
iOS version: 15.6.1
Network Connectivity: Wifi
This is how we registered PushKit
private func registerForVoIPPushes() {
self.voipRegistry = PKPushRegistry(queue: pushRegistryQueue)
self.voipRegistry.delegate = self
self.voipRegistry.desiredPushTypes = [.voIP]
}
We conforms the PKPushRegistryDelegate this way
extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let deviceToken = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
updateVoIPToken(deviceToken)
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: #escaping () -> Void) {
DDLogDebug("Incoming call voip push: \(payload.dictionaryPayload)")
handleIncomingCall(payload: payload.dictionaryPayload)
completion()
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
DDLogDebug("didInvalidatePushTokenFor type: \(type)")
}
}
This is how server sends voip push payload
path = '/3/device/{0}'.format({deviceToken}})
request_headers = {
'apns-expiration': '0',
'apns-priority': '10',
'apns-topic': 'com.companyname.app.voip',
'apns-push-type':'voip',
'authorization': 'bearer {auth-token}'
}
# Open a connection the APNS server
conn = HTTP20Connection('api.push.apple.com:443')
conn.request(
'POST',
path,
payload,
headers=request_headers
)
resp = conn.get_response()
print(resp.status)
print(resp.read())
The output http status code shows 200 but push actually not delivered.
Same codebase is woking fine with other devices.
I appreciate any helps and suggestions.
Thanks.

Push Kit Not receiving pushCredentials token

I am new in integrating Push Kit so I am not able to receive the pushCredentials token please suggest me solution.
Below is my code :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// For debugging
//OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)
//Enable all notification type.
let notificationSettings = UIUserNotificationSettings(types: [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound] , categories: nil)
//register the notification settings
application.registerUserNotificationSettings(notificationSettings)
return true
}
extension AppDelegate {
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
//register for voip notifications
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.desiredPushTypes = Set([PKPushType.voIP])
voipRegistry.delegate = self;
print("didRegisterUserNotificationSettings")
}
}
extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, forType type: PKPushType) {
print("voip token: \(pushCredentials.token)")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
let payloadDict = payload.dictionaryPayload["aps"] as? Dictionary<String, String>
let message = payloadDict?["alert"]
//present a local notifcation to visually see when we are recieving a VoIP Notification
if UIApplication.shared.applicationState == UIApplicationState.background {
let localNotification = UILocalNotification();
localNotification.alertBody = message
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = UILocalNotificationDefaultSoundName;
UIApplication.shared.presentLocalNotificationNow(localNotification);
}
else {
print(message)
// dispatch_async(DispatchQueue.main, { () -> Void in
//
// let alert = UIAlertView(title: "VoIP Notification", message: message, delegate: nil, cancelButtonTitle: "Ok");
// alert.show()
// })
}
NSLog("incoming voip notfication: \(payload.dictionaryPayload)")
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
NSLog("token invalidated")
}
}
extension UIApplicationState {
//help to output a string instead of an enum number
var stringValue : String {
get {
switch(self) {
case .active:
return "Active"
case .inactive:
return "Inactive"
case .background:
return "Background"
}
}
}
}
Am I missing something please suggest.
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, forType type: PKPushType) {
let deviceTokenString = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
print("deviceTokenString \(deviceTokenString)")
}

didReceiveIncomingPushWithPayload Not working when app is killed

I'm facing an issue in didReceiveIncomingPushWithPayload method as it doesn't fire when app is killed/terminated. But working perfectly when app is in background.
After investigating, I found some people recommend using the new version as this one is already deprecated
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: #escaping () -> Void) {
DispatchQueue.main.async(execute: {() -> Void in
completion()
})
}
It works good but this method is only iOS 11+ so it doesn't work for iOS 9. Any suggestions?
I get it like this and it works on iOS 10 and 11.
//available(iOS, introduced: 8.0, deprecated: 11.0)
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) {
// no-op
}
}
//available(iOS 11.0, *)
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: #escaping () -> Void) {
//your code
completion()
}
Hope it helps.

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!

PushKit PKPushRegistryDelegate does not get callbacks

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:

Resources