How to find device token for push notifications in iPhone app

Apple Push Notifications Service (APN’S) propagates push notifications to devices having apps registered to receive those notifications. Provider connects with APN through a persistent and secure channel while monitoring incoming data for their apps. When a new data for an app arrives, the provider prepares and sends a notification through the channel to APN’S, which pushes notification to a target device.

So for push notification to be delivered to target device, the user needs to give approval for the app to receive push notifications and they need to registered to channel using device token.

Device token for sandbox and production are two different things. So if you are testing against sandbox mode then you developer certificates and if you are testing for production builds then test it against the ad hoc builds.

Here is the snippet in AppDelegate.m file, which will help you to get device token for a device:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

NSLog(“APNS device token is %@”, deviceToken);

NSString *deviceTokenString = [NSString stringWithFormat:”%@”, deviceToken];

}

This will log the device token for a device, using which you can send a push notification to the device directly.

Feel free to comment to this post or you can also reach me at naik899@gmail.com. Thanks for stopping by !!!

Leave a Reply

Your email address will not be published. Required fields are marked *