I’m getting some major grief while trying to extract the device token in my applications. So far, I have
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register for push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
And then
-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWith:DeviceToken:(NSData *)deviceToken
{
NSString *str = [deviceToken description];
NSLog(@"%@", str);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
Here’s the deal.
my iOS Simulator: I get
Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x5813d20 {NSLocalizedDescription=remote notifications are not supported in the simulator}
as expected.
On my iPod Touch, 2nd gen, running iOS 4.2, neither of the callbacks are ever invoked. The same happens on my coworkers iPhone 4s running iOS 5.1.1
Finally, on another coworkers iPhone 4 running iOS.5.1.1, it seems to be returning that the device token is “com.apple.mobileconfig”… which is very odd.
I’ve verified that notifications are enabled for the app on my device. I’ve also verified that my app identifier bundle is set up correctly in xCode.
EDIT: I have no clue what happened, but, a few days after posting this thread, I plugged an iPhone 4 into my mac and the device token callbacks just started working in debug mode, and then on everyone else’s devices also. I made a few changes to the provisioning profile (had to add the new device’s UDID, etc), so that could have knocked something glitchy out of it. Not really sure.
EDIT2: It appears there was an extra colon in the didRegister callback, right before DeviceToken …
not
notice the extra colon in the second, incorrect version… stupid mistake.
moral of story: be careful copy and pasting 🙂