Device token not generated and push notification not working

Hello


Last day in our app push notifications were working but today not.


After debugging I found that device token was not generated. following method called to generate device token but its not working.

didRegisterForRemoteNotificationsWithDeviceToken


Complete code to handle push notifications is as follows -

// Added into the didFinishLaunchingWithOptions method
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

    }
    else
    {
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }

// Handling of push notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    /
    if (notificationSettings.types != UIUserNotificationTypeNone) {
        /
        [application registerForRemoteNotifications];
    } else {
        /
        NSDictionary* data = [NSDictionary dictionaryWithObject:@"" forKey:@"deviceToken"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationsRegistered" object:self userInfo:data];
        /
        /
    
    }

    /
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{

    NSString *newToken = [deviceToken description];

    newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];

    newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];

    self.myDeviceToken = newToken;
    [CLServerDataManager setDeviceToken:newToken];

    NSLog(@"DEVICE_TOKEN = %@", newToken);

    [self showAlertViewWithTitle:@"Notification" andMessage:newToken];


}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{

#if TARGET_IPHONE_SIMULATOR
    NSLog(@"Failed to get token, error: %@", error);
    [CLServerDataManager setDeviceToken:@"dummy"];
    self.myDeviceToken = @"dummy";
#endif

    if (self.myDeviceToken == nil) {
        self.myDeviceToken = @"dummy";
    }
    [self showAlertViewWithTitle:@"Notification" andMessage:self.myDeviceToken];

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
}
 

Replies

Experiencing this same problem with PushKit registration. No callbacks occur for sandbox env.

I am also facing same problem.