Reputation:
I Have implemented following code but not getting the Device Token?
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
}
Upvotes: 1
Views: 1531
Reputation: 426
For registering your device with APNs, you will first have to call
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
this is usually written in your AppDelegate (in didFinishLaunching ). Then make sure you have implemented the
didRegisterForRemoteNotificationsWithDeviceToken
which provides you with the device token and
didFailToRegisterForRemoteNotificationsWithError
which gives you the error your code might have encountered.
Upvotes: 0
Reputation: 3996
Are you trying inside of the simulator ? Push notification and related appdelagate events doesn't work on simulator.
If you are using the device, Make sure that bundle identifier of your application must be same with your push ssl bundle identitifier which you defined during creating AppID on iphone privisioning protal.
Upvotes: 1
Reputation: 13433
If you don't already, you should have a call to registerForRemoteNotificationTypes
in your didFinishLaunchingWithOptions
. Something along the lines of:
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
You should also have a didFailToRegisterForRemoteNotificationsWithError
method that gets called if registration fails. The NSerror it gets should tell you more about why it might be failing.
Upvotes: 4