1

there is notification feature in my application , its working for all.But only for few members device token itself is coming null.Can anyone help me please to resolve this issue? They are using iOS 9.2 version and device is iPhone 6 and 5s.

Thank you all in advance.

kb920
  • 3,039
  • 2
  • 33
  • 44
veebha
  • 47
  • 1
  • 9
  • Try by restarting device twice. – Avijit Nagare Jan 28 '16 at 06:06
  • When app ask for push notification permission and user deny (Don't Allow) then didRegisterForRemoteNotificationsWithDeviceToken delegate method not call. So you will not get device token value. – kb920 Jan 28 '16 at 06:10
  • Thanks for quick response.I asked them to restart device and delete app and install it again , but still they have same issue. – veebha Jan 28 '16 at 06:19

3 Answers3

2

Add below code in your didFinishLaunchingWithOptions in AppDelegate.m:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

May be this will also work for iOS version greater than 8.0.

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
2

Two possibilities

One

You missed below code for iOS 8 and above

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    NSLog(@"ios8 app");
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    NSLog(@"lower ios8 app");
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}

OR

Two

User click Don't allow for Push


Edit 1

If this is happening with some users, then those users iPhone are Jailbroken. Make sure who get device token as null are not Jailbroken

Edit 2

To check if jailbroken or not

NSString *path = @"/Applications/Cydia.app";
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];

if (fileExists) {
    //device is jailbroken
} else {
    //device is not jailbroken
}

Reference

OR

NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
if ([info objectForKey: @"SignerIdentity"] != nil)
{
/* do something */
}

Reference

Community
  • 1
  • 1
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
1

go to settings -> your app -> Notifications -> toggle on Allow Notification or try

if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert| UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge)];
}

in didFinishLaunchingWithOptions in AppDelegate.m

vaibby
  • 1,255
  • 1
  • 9
  • 23