I want to implement VoIP notifications in my iOS application, But the didUpdatePushCredentials method never got called, I can't get the device token.
I had implemented APNS in the application, May these two services conflict ?
Here is my AppDelegate codes
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
LOGI(@"%@", NSStringFromSelector(_cmd));
//register for voip notifications
self->pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
[self->pushRegistry setDelegate:self];
[self->pushRegistry setDesiredPushTypes:[NSSet setWithObject:PKPushTypeVoIP]];
NSLog(@"VoIP push registered");
}
#pragma mark - VoIP push methods
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
NSLog(@"voip token: %@", credentials.token);
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
NSDictionary *payloadDict = [payload.dictionaryPayload valueForKey:@"aps"];
NSString *message = (NSString *)[payloadDict valueForKey:@"alert"];
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = [message stringByAppendingString:@" - voip"];
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = @"notes_of_the_optimistic.caf";
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"VoIP notification" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
});
}
NSLog(@"incoming voip notfication: %@", payload.dictionaryPayload);
}
- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(NSString *)type {
NSLog(@"Voip token invalidate");
}
Any solution to get it working ?
If you're running a newer xcode (I'm on xcode 9) then VOIP is not in the Background section on the Capabilities tab. This will prevent didUpdatePushCredentials
from being called!
The trick is you have to go in your plist, and in Required Background Modes
you need to add App provides Voice over IP services
.
I can't believe Apple has done this to us. I wasted an 8 hour work day looking for this simple fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With