Skip to content

Instantly share code, notes, and snippets.

@snatchev
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snatchev/0390b91c341051f466dc to your computer and use it in GitHub Desktop.
Save snatchev/0390b91c341051f466dc to your computer and use it in GitHub Desktop.
register VoIP push notifications with ZeroPush: https://zeropush.com/guide/guide-to-pushkit-and-voip
#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, PKPushRegistryDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
#import "ZeroPush.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
PKPushRegistry * voipRegistry = [[PKPushRegistry alloc] initWithQueue: dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
[[ZeroPush shared] registerDeviceToken:credentials.token];
}
-(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSDictionary *data = [payload.dictionaryPayload objectForKey:@"aps"];
notification.alertBody = [data objectForKey:@"alert"];
notification.category = [data objectForKey:@"category"];
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment