mblawrence / javapns

Automatically exported from code.google.com/p/javapns
0 stars 0 forks source link

Device Token has length of [40] and not the required 64bits Error? #64

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1.Got my device udid.  The example below is edited (not my real udid)
2. called pushManager.addDevice( "myiphone", 
"9d5d57c2a0b3d74125740c03aa3bbf18ac833c24" );
3.Got error: Device Token has length of [40] and not the required 64bits

Is their a different token that I must use which isn't the device udid?

My Iphone is a 3G model, but running IOS 4.2
The server is Windows/JDK 1.6

Thanks!

Original issue reported on code.google.com by rhodebump@gmail.com on 2 Sep 2011 at 12:09

GoogleCodeExporter commented 8 years ago
Hello,

You need the deviceToken, not device UID. The device token is returned by apple 
when you activate pns for your application.  You should write this in the 
ApplicationDidFichishedLaunching...

[[UIApplication sharedApplication] 
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | 
UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

and create those method to get the token:
- (void)application:(UIApplication*)application 
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)dt
{
    NSLog(@"My token is: %@", dt);  // dt is the token.
      // here is what i do to get a good 64bit string that will be used for a token
    NSString *tt = [NSString stringWithFormat:@"%@",dt];
    NSString *deviceToken = [[tt substringWithRange:NSMakeRange(1, [tt length]-2)]stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"My token is: %@", deviceToken);
// then do whatever your want to keep the token
}

- (void)application:(UIApplication*)application 
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

Original comment by patrice....@gmail.com on 3 Sep 2011 at 5:38

GoogleCodeExporter commented 8 years ago
Closing issue, since the problem was that a device UDID was passed to the 
library instead of a device token.

The error reported by the library was slightly incorrect though, as it stated 
the token had to be 64bits long.  I have fixed it to say "64 bytes".  The fix 
will be in my next commit to the 2.0 branch.

Original comment by sype...@gmail.com on 7 Sep 2011 at 4:40

GoogleCodeExporter commented 8 years ago
Hi thank you for above explaination. I am implementing push notification using 
javapans . I am little bit confusion  on DeviceToken concept .I understood that 
UDID is different from DeviceToken and  i got device token using above code. My 
doubt is can i use this DeviceToken for multipleDevices..

Original comment by rajarame...@gmail.com on 4 Mar 2013 at 9:13