0

I get a new iPhone and when i tried to test it with a Xcode project with push notifications , it doesn't get token , always failed to get token , i think this because when i was creating the certificate i didn't mark on the device , now i want to add this device to the testing and get token what i should do ??

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);

}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}
Larme
  • 24,190
  • 6
  • 51
  • 81
mohamed
  • 243
  • 3
  • 14
  • http://stackoverflow.com/questions/11045406/apple-push-notification-registration-device-token-receive-clarification – iPatel Apr 22 '14 at 10:28
  • a lot of thanks :) ,, how to do this step how ever the application is already configured " set Provisioning profile in which you have added your device UDID" – mohamed Apr 22 '14 at 10:35
  • http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 – iPatel Apr 22 '14 at 10:40
  • i did all of this , i want to add a new device – mohamed Apr 22 '14 at 10:49
  • Check This [link](http://stackoverflow.com/questions/15804332/how-to-add-udid-to-the-provisioning-profile) or this [link](http://www.youtube.com/watch?v=xT1_Um0eBJM) after adding new device edit your provisioning and select device then regenerate it and install it. then select Provisioning profile in xcode. – i-Maddy Apr 22 '14 at 10:58

1 Answers1

2

For that you should first set Provisioning profile in which you have added your device UDID. then Add below code to register Pushnotification in device. so when you run your app first time it will ask you for permission .

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

If you allow then below delegate will be called. and it will give you device token.

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString *strDeviceToken = [[[[[deviceToken description]stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""]stringByReplacingOccurrencesOfString:@" " withString: @""]copy];
    NSLog(@"%@",strDeviceToken);
}

If you dont allow then below delegate method will be called

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

Maybe it will help you.

i-Maddy
  • 84
  • 4
  • a lot of thanks :) ,, how to do this step how ever the application is already configured " set Provisioning profile in which you have added your device UDID" – mohamed Apr 22 '14 at 10:31
  • You should read this whole [Raywenderlich Document](http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1) to understand better. Follow this step and you are done. :) – i-Maddy Apr 22 '14 at 10:35