following this promising tutorial from nickjf89 I try to implement Push Notification in a vanilla Cordova project.
Until now, I'm able to get communication with the socket, when I push data from the Pusher console, all works, so I exclude any misconfiguration on Pusher API.
The "only" thing which fail is the actual Push Notification.
Looking at the Push Notification console, I see my request arriving on my cordova channel.
But in the xCode console, I don't see the expected log from NSLog(@"Received remote notification: %@", userInfo);
I suspect I got an issue with my AppDelegate.m
which is below.
#import "AppDelegate.h"
#import "MainViewController.h"
@import UserNotifications;
#import <PusherSwift/PusherSwift-Swift.h>
@interface AppDelegate ()
@property (nonatomic, retain, readwrite) Pusher *pusher;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.viewController = [[MainViewController alloc] init];
self.pusher = [[Pusher alloc] initWithKey:@"here_i_put_my_pusher_app_key"];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
// Enable or disable features based on authorisation.
}];
[application registerForRemoteNotifications];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Registered for remote notifications; received device token");
[[[self pusher] nativePusher] registerWithDeviceToken:deviceToken];
[[[self pusher] nativePusher] subscribeWithInterestName:@"cordova"];
NSLog(@"Seeems token stuff works");
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Received remote notification: %@", userInfo);
}
@end
Ok, one time again, the issue was between the chair and the keyboard... I found the fix, it was related to the APNs certificate uploaded on Pusher and the
my-app-name.entitlements
where APS environment was set on production instead of development.All fixed and functional, great new feature from Pusher!