2

I wrote 3 apps to get the device token in my iPad, but each app got different device token.

app1:4e8eb1d864c80fd8426615cd8ca4133c8bde78c30910cd1a8b82c917b612f38d
app2:2645100209412c457e87744c0af9ff323e28f6b2195c0fa9b835ddeebfe1391b
app3:f5958b3bad17feda02e64f9814f01cfafdda0b8283977214916c3d7eaa8b8dc8

Is that normal? I have checked some information which says that different apps on a same device will get a same device token... but according to my testing it seems not true.

Any comment would be appreciated :)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeNewsstandContentAvailability];
}

return YES;

}

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

NSString *newToken =[deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"*******************");
NSLog(@"Token%@",newToken);}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"errorwwwwww:%@",[error description]);}
Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
  • can you upload some code on how you create the device token? – YYfim Feb 05 '15 at 08:17
  • can you point to the information "which says that different apps on a same device will get a same device token"? this isn't true, this behaviour is normal, check my answer :) – nburk Feb 05 '15 at 08:33

2 Answers2

3

It is perfectly normal!

A device token identifies a device and an app both at the same time. Think about it, it makes perfectly sense since the device tokens are used to identify the app within iOS when push notifications are received. If every app would return the device token, iOS wouldn't know where to deliver the push notification once it arrives at the device.

nburk
  • 22,409
  • 18
  • 87
  • 132
  • Actually it could, since each App ID has its own SSL certificate to connect to APN server. – CarmeloS Feb 05 '15 at 08:41
  • well yes theoretically you're right. but imo that wouldn't be very practical and the way apple chose to design the APNS infrastructure is a sign for that I think. i was working in a company where we deployed whitelabel apps, thus it was the more important to being able to differentiate _between_ apps on the same device as well, for these kinds of situations it's a little easier to just distribute device tokens for device and app both at the same time as I stated in the answer – nburk Feb 05 '15 at 08:44
  • @nburk thank you very much! I read these information from some chinese blog... and i realized that their information was wrong.the wrong information are just copy again and again.i feel sorry to asking these question. – facebook-100001564118706 Feb 05 '15 at 09:12
  • don't be sorry, you couldn't know better and it's perfectly fine to come to SO to seek for clarity :) just beware that not everything you read on the web is necessarily true – nburk Feb 05 '15 at 09:14
0

Its perfectly normal.The device token changes with the bundle id of the app and the certificate used to create it.

Tushar
  • 88
  • 7