triston
triston

Reputation: 493

How to get iphone device token for push notification?

I am trying to use Remote Push Notification in my app, and I was trying to have this test out within my app, but i couldn't reset the alert popup after i tap on "Allow" at the very beginning.

so my question is:

Do i still get the device token even when the user tap "Don't Allow" in the alert popup?

Upvotes: 1

Views: 4890

Answers (3)

Divya Jain
Divya Jain

Reputation: 119

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

{

    NSLog(@"My token is: %@", deviceToken);

}

In this way you get iPhone device token

Upvotes: 0

Nitin
Nitin

Reputation: 7471

Use following delegates method...

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

    NSLog(@">>%@",deviceToken);// this will give  you token
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{

    NSLog(@">>%@",error); // this will gave you error msg with description.

}

Hope, this will help you..

Upvotes: 0

Saad
Saad

Reputation: 8947

use appDelegate method

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        self.mDeviceToken = deviceToken;

        //Removing the brackets from the device token
        NSString *tokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];

        NSLog(@"Push Notification tokenstring is %@",tokenString);

    }   

and in case error

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{

    NSString* s=[[NSString alloc] initWithFormat:@"%@",error];
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:s delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [s release];
// lert because your device will not show log
}

Upvotes: 3

Related Questions