iPhone registerForRemoteNotificationTypes does not generate an error but does not fire delegate that gives device token

Rick Leinecker picture Rick Leinecker · Jul 11, 2010 · Viewed 23.6k times · Source

I am developing an iPhone app that needs push notification. I followed the instructions for creating the certifications and modifying the app ID. I am not totally sure I did this correctly, but I did follow the directions. Any idea how I can check to see if this is OK?

When I ran in the emulator I did get an error message saying that the emulator did not support push notifications. This was somewhat expected.

BTW: I have seem this question out there a few times. It always seems to be with a jail-broken phone. My phone is NOT jail-broken.

But when I debug on the iPhone the didRegisterForRemoteNotificationsWithDeviceToken method is never fired off. I will really appreciate some help. My code follows.

-(void)applicationDidFinishLaunching:(UIApplication *)application 
{    
   rootController.delegate = self;
   [window addSubview:rootController.view];
   [window makeKeyAndVisible];

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

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{ 
   NSString *str = 
    [NSString stringWithFormat:@"%@",deviceToken];
    NSLog(str);
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err 
{ 
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(str);    
}

Answer

Patrick Goley picture Patrick Goley · Aug 22, 2012

Usually if didRegisterForRemoteNotificationsWithDeviceToken is never called, it is because you are using a provisioning profile that is not APS-entitled. If you app is a production app, it must be signed with a distribution profile for pushes to work. If it is a development app, you must sign it with a development profile.

EDIT: It is also worthy to note that the provisioning profile must use an explicit bundle id. Pushes sent to anything signed with a wildcard profile will not be delivered.