Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device token getting Nil

I have a strange issue, Some of my users are returning blank (or null) device tokens for Apple Push Notification. It happening only some of user's only not for all user's,

Here's my code,

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

   #if !TARGET_IPHONE_SIMULATOR

       [_globalKRData setPreferences:deviceToken withKey:kPushToken]; // Preferences 

       PFInstallation *currentInstallation = [PFInstallation currentInstallation];
       [currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[@"global"];
       [currentInstallation saveInBackground];

    #endif

}

Is it possible if device is Jail break that's why i getting nil device token ?

Update

For example First time user allowing push notification and it works properly,

Now user go to setting and disable the notification from setting's

Disable notification

Then after it i will not get device token that was fine but problem is now user uninstall the app,

Then after Download the app again then after didRegisterForRemoteNotificationsWithDeviceToken not called so i getting nil device token and when i check setting it will showing notification on

like image 793
Mayank Patel Avatar asked Dec 02 '15 04:12

Mayank Patel


People also ask

How can we get device token for Android?

Whenever your Application is installed first time and open, MyFirebaseMessagingService created and onNewToken(String token) method called and token generated which is your Device Token or FCM Token.

What is device token in Apple Push Notification?

'The device token you provide to the server is analogous to a phone number; it contains information that enables APNs to locate the device on which your client app is installed. APNs also uses it to authenticate the routing of a notification. '

What is device token in android?

Push token (device token) - is a unique key for the app-device combination which is issued by the Apple or Google push notification gateways. It allows gateways and push notification providers to route messages and ensure the notification is delivered only to the unique app-device combination for which it is intended.

Is device token unique in Android?

The Device Tokens are NOT unique to the phone-app pairing. They are unique to the phone only. If you have multiple apps with push on the same phone they will all use the same Device Token.


1 Answers

In iOS8 I have deleted my app before that i turn OFF the notification,then i run my application did register is not called,then i again go to the settings and find that Allow notification is ON, but the "didRegisterForRemoteNotification" didn't get a call,

Then I turn "Allow notification" to OFF and again i turn it ON, then i come to my app I found the device token, But its working fine after that, but user have to turn it off by manually and again he has to turn it on, of course its a bug of apple,

It will work fine in iOS 9

like image 183
satheesh Avatar answered Sep 21 '22 10:09

satheesh