VoIP Pushes
This guide addresses sending VoIP push notifications
In iOS 8 Apple introduced PushKit, and VoIP pushes - a new type of push notifications. On top of the standard push functionality, a VoIP push allows the app to execute code before displaying the notification to the user.

IMPORTANT

You can only create a VoIP certificate in production mode, not development mode. Therefore, in Pushwoosh iOS app configuration you should always use Production gateway for VoIP certificates.
1. In your AppDelegate.h import PushKit framework, add PKPushRegistryDelegate protocol and create the PKPushRegistryproperty:
Swift
Objective-C
1
import PushKit
2
3
@UIApplicationMain
4
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {
5
6
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: DispatchQueue.main)
Copied!
1
#import <PushKit/PushKit.h>
2
@interface AppDelegate : UIResponder <UIApplicationDelegate, PKPushRegistryDelegate>
3
@property (nonatomic, strong) PKPushRegistry* voipRegistry;
Copied!
2. In - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {add:
Swift
Objective-C
1
// handling push on app start
2
PushNotificationManager.push().handlePushReceived(launchOptions)
3
4
// make sure we count app open in Pushwoosh stats
5
PushNotificationManager.push().sendAppOpen()
6
7
// register for push notifications!
8
PushNotificationManager.push().registerForPushNotifications()
9
10
voipRegistry.delegate = self
11
voipRegistry.desiredPushTypes = [PKPushType.voIP]
Copied!
1
// handling push on app start
2
[[PushNotificationManager pushManager] handlePushReceived:launchOptions];
3
4
// make sure we count app open in Pushwoosh stats
5
[[PushNotificationManager pushManager] sendAppOpen];
6
7
// register for push notifications!
8
[[PushNotificationManager pushManager] registerForPushNotifications];
9
10
_voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
11
_voipRegistry.delegate = self;
12
_voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
Copied!
3. Add the following methods to your AppDelegate class:
Swift
Objective-C
1
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
2
PushNotificationManager.push().unregisterForPushNotifications()
3
}
4
5
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
6
PushNotificationManager.push().handlePushReceived(payload.dictionaryPayload)
7
}
8
9
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, forType: PKPushType) {
10
PushNotificationManager.push().handlePushRegistration(pushCredentials.token)
11
}
Copied!
1
- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(NSString *)type
2
{
3
//unsubscribe from push notifications
4
[[PushNotificationManager pushManager] unregisterForPushNotifications];
5
}
6
7
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
8
{
9
//push received
10
[[PushNotificationManager pushManager] handlePushReceived:payload.dictionaryPayload];
11
}
12
13
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
14
{
15
[[PushNotificationManager pushManager] handlePushRegistration:credentials.token];
Copied!
4. Enable Voice over IP in Background Modes:
5. Upload your VoIP certificate to Pushwoosh Control Panel according to Configuration Guide, and choose the Production gateway.
That’s it!
As opposed to the standard push, VoIP pushes do not play notification sounds, or display alerts. However, they wake up your app in the background, which allows you to schedule a local notification.
Last modified 10mo ago
Copy link